#include <algorithm>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

int main() {
  int T, N;
  for (cin >> T; T--;) {
    cin >> N;
    vector<tuple<int,int,int,int>> v(N);
    bool fail = false;
    for (auto& [t,s,f,c] : v) {
      cin >> t >> s >> f >> c;
      if (s == 0) fail = true;
    }
    if (fail) { cout << "impossible" << endl; continue; }

    sort(v.begin(), v.end(), [](auto const& a, auto const& b) {
      auto [ta,sa,fa,ca] = a;
      auto [tb,sb,fb,cb] = b;
      return ta*(sa+fa+ca) * cb < tb*(sb+fb+cb) * ca;
    });
    double p = 1.0, x = 0.0;
    for (auto [t,s,f,c] : v) {
      x += p * t*(s+f+c)/double(s+c);
      p *= s/double(s+c);
    }
    cout << setprecision(9) << x/p << endl;
  }
}
