#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'
const LL M = (LL)1e9+7;
struct pt
{
LL x;
int a;
int b;
};
bool operator <(const pt &a,const pt &b)
{
if(a.a == a.b) return true;
if(b.a == b.b) return false;
LL d1 = a.x*(b.a-b.b);
LL d2 = b.x*(a.a-a.b);
return d2<d1;
}
int main()
{
ios_base::sync_with_stdio(0);
cout.precision(15);
cout.setf(ios::fixed);
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
vector <pt> v(n);
for(LL i=0;i<n;i++)
{
cin >> v[i].a>>v[i].b>>v[i].x;
// v[i].p /= 1e7;
}
sort(v.begin(),v.end());
LL ans = 0;
LL c1 = 0, c2 = (LL)1e7;
for(LL i=0;i<n;i++)
{
ans += c1*v[i].b + c2*v[i].a;
c1 += v[i].x;
c2 -= v[i].x;
}
double ans2 = ans/1e7;
cout<<ans2<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnR5cGVkZWYgbG9uZyBsb25nIExMOyAgCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGZpbGxjaGFyKGEsIHgpIG1lbXNldChhLCB4LCBzaXplb2YoYSkpCiNkZWZpbmUgTVAgbWFrZV9wYWlyCiNkZWZpbmUgUEIgcHVzaF9iYWNrCiNkZWZpbmUgZW5kbCAnXG4nCgpjb25zdCBMTCBNID0gKExMKTFlOSs3OwoKc3RydWN0IHB0CnsKCUxMIHg7CglpbnQgYTsKCWludCBiOwp9OwoKYm9vbCBvcGVyYXRvciA8KGNvbnN0IHB0ICZhLGNvbnN0IHB0ICZiKQp7CglpZihhLmEgPT0gYS5iKSByZXR1cm4gdHJ1ZTsKCWlmKGIuYSA9PSBiLmIpIHJldHVybiBmYWxzZTsgCgoJTEwgZDEgPSBhLngqKGIuYS1iLmIpOwoJTEwgZDIgPSBiLngqKGEuYS1hLmIpOwoKCXJldHVybiB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