#include <bits/stdc++.h>
using namespace std;
double helen(double a, double b, double c) {
double p = (a + b + c) / 2;
double res = sqrt(p * (p - a) * (p - b) * (p - c));
return res;
}
int T;
int n;
typedef pair<int, int> PII;
typedef long long ll;
int ma1, ma2, ma3;
void getma(int x) {
if (x > ma1) {
ma3 = ma2;
ma2 = ma1;
ma1 = x;
} else if (x > ma2) {
ma3 = ma2;
ma2 = x;
} else if (x > ma3) {
ma3 = x;
}
}
map<int, ll, greater<int> > tbl;
int main() {
scanf("%d",&T);
while (T--) {
scanf("%d", &n);
tbl.clear();
ma1 = 0, ma2 = 0, ma3 = 0;
ll lsum = 0;
for (int i = 1; i <= n; i++) {
int a;
ll b;
scanf("%d%lld", &a, &b);
lsum += b;
if (tbl.find(a) != tbl.end()) {
tbl[a] += b;
} else {
tbl[a] = b;
}
for (int j = 1; j <= min(b, 3ll); j++) {
getma(a);
}
}
if (lsum < 3 || ma2 + ma3 <= ma1 /*|| (ma1!=ma2 &&ma1!=ma3)*/) {
puts("-1");
continue;
}
bool flag = false;
for (map<int, ll, greater<int> >::iterator it = tbl.begin(); it != tbl.end(); it++) {
// printf("debug : %d\n", it->first);
if (it->second >= 3) {
printf("%.9lf\n", helen(it->first, it->first, it->first));
flag = true;
break;
}
if (next(it) == tbl.end())
break;
ll t1 = it->second;
double s1 = it->first;
ll t2 = next(it)->second;
double s2 = next(it)->first;
if (t1 + t2 >= 3 && t1 == 1 && s2 + s2 > s1) {
printf("%.9lf\n", helen(s1, s2, s2));
flag = true;
break;
}
if (t1 + t2 >= 3 && t1 == 2) {
printf("%.9lf\n", helen(s1, s1, s2));
flag = true;
break;
}
}
if (!flag) {
puts("-1");
}
}
return 0;
}