#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;
	}	

}
