#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;
#define mxs 1010
#define inf 9999999999999.00
double loc [ 2 ] [ mxs ] , cost [ mxs ];
double value [ 25 ] [ mxs ];
int population [ mxs ] , parent [ mxs ] , sparse [ mxs ] [ 22 ] , level [ mxs ];
vector < pair < int , double > > graph [ mxs ];
int p , q , a , b , n , t , m , c , k , log_;
bool visited [ mxs ];
priority_queue < pair < double , int > > pq;
double x , y , z , w , ans , sum;
void make_graph();
void mst();
void clear_();
void dfs( int source );
void make_sparse();
void solution_finder();
double lca();
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
scanf("%d",&t);
while ( t-- )
{
clear_();
scanf("%d",&n);
for ( int i = 1; i <= n; i++ )scanf("%lf%lf %d",&loc [ 0 ] [ i ] , &loc [ 1 ] [ i ], &population [ i ] );
make_graph();
mst();
level [ 1 ] = 0;
parent [ 1 ] = -1;
cost [ 1 ] = 0.00;
dfs( 1 );
make_sparse();
solution_finder();
printf("%.2f\n",ans);
}
return 0;
}
void clear_()
{
//memset( value , 0.00, sizeof value );
memset( sparse , -1, sizeof sparse );
for ( int i = 0; i <= 1002; i++ )
{
visited [ i ] = 0;
graph [ i ].clear();
cost [ i ] = inf;
}
}
void make_graph()
{
for ( int i = 1; i <= n; i++ )
{
for ( int j = 1; j <= n; j++ )
{
if ( i == j )continue;
x = loc [ 0 ] [ i ] - loc [ 0 ] [ j ];
x *= x;
y = loc [ 1 ] [ j ] - loc [ 1 ] [ i ];
y *= y;
x += y;
x = (double)sqrt( x );
graph [ i ].push_back ( { j , x } );
graph [ j ].push_back ( { i , x } );
}
}
}
void mst()
{
parent [ 1 ] = -1;
pq.push( { 0.00 , 1 } );
cost [ 1 ] = 0.00;
while ( !pq.empty() )
{
a = pq.top().second;
pq.pop();
if ( visited [ a ] )continue;
visited [ a ] = 1;
int sz = graph [ a ].size();
for ( int i = 0; i != sz; i++ )
{
b = graph [ a ] [ i ].first;
x = graph [ a ] [ i ].second;
if ( !visited [ b ] && cost [ b ] > x )
{
pq.push( { x , b } );
cost [ b ] = x;
parent [ b ] = a;
}
}
}
for ( int i = 0; i <= n; i++ )
{
graph [ i ].clear();
visited [ i ] = 0;
}
sum = 0.00;
for ( int i = 2; i <= n; i++ )
{
a = parent [ i ];
sum += cost [ i ];
graph [ a ].push_back ( { i , cost [ i ] } );
graph [ i ].push_back ( { a , cost [ i ] } );
parent [ i ] = -1;
}
}
void dfs( int source )
{
visited [ source ] = 1;
int sz = graph [ source ].size();
for ( int i = 0; i != sz; i++ )
{
int lol = graph [ source ] [ i ].first;
if ( !visited [ lol ] )
{
parent [ lol ] = source;
level [ lol ] = level [ source ] + 1;
cost [ lol ] = graph [ source ] [ i ].second;
dfs( lol );
}
}
}
void make_sparse()
{
value [ 0 ] [ 1 ] = 0.00;
for ( int i = 2; i <= n; i++ )sparse [ 0 ] [ i ] = parent [ i ],value [ 0 ] [ i ] = cost [ i ];
for ( int j = 1; ( 1<<j ) <= n ; j++ )
for ( int i = 2 ; i <= n; i++ )
if ( sparse [ j - 1 ] [ i ] != -1 )
{
sparse [ j ] [ i ] = sparse [ j - 1 ] [ sparse [ j - 1 ] [ i ] ];
value [ j ] [ i ] = max ( value [ j - 1 ] [ i ] , value [ j - 1 ] [ sparse [ j - 1 ] [ i ] ] );
}
}
void solution_finder()
{
ans = 0.00;
for ( int i = 1; i <= n; i++ )
for ( int j = 1; j <= n; j++ )
{
if ( i == j )continue;
p = i , q = j;
w = lca();
x = ( double )( population [ i ] + population [ j ] );
ans = max ( ans , ( double )( x / ( sum - w ) ) );
}
}
double lca()
{
if ( level [ p ] < level [ q ] )swap( p , q );
log_ = 1;
while ( level [ p ] >= ( 1<< ( log_ + 1 ) ) )log_++;
w = 0.00;
for ( int i = log_; i >= 0; i-- )
if ( sparse [ i ] [ p ] != -1 && ( level [ p ] - ( 1<<i ) ) >= level [ q ] )
{
w = max ( w , value [ i ] [ p ] );
p = sparse [ i ] [ p ];
}
if ( p == q )return w;
for ( int i = log_; i >= 0; i-- )
{
if ( sparse [ i ] [ p ] != -1 && sparse [ i ] [ p ] != sparse [ i ] [ q ] )
{
w = max ( w , value [ i ] [ p ] );
w = max ( w , value [ i ] [ q ] );
p = sparse [ i ] [ p ];
q = sparse [ i ] [ q ];
}
}
w = max ( w , value [ 0 ] [ p ] );
w = max ( w , value [ 0 ] [ q ] );
return w;
}
I3ByYWdtYSBjb21tZW50KGxpbmtlciwgIi9zdGFjazoyMDAwMDAwMDAiKQojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIG14cyAxMDEwCiNkZWZpbmUgaW5mIDk5OTk5OTk5OTk5OTkuMDAKZG91YmxlIGxvYyBbIDIgXSBbIG14cyBdICwgY29zdCBbIG14cyBdOwpkb3VibGUgdmFsdWUgWyAyNSBdIFsgbXhzIF07CmludCBwb3B1bGF0aW9uIFsgbXhzIF0gLCBwYXJlbnQgWyBteHMgXSAsIHNwYXJzZSBbIG14cyBdIFsgMjIgXSAsIGxldmVsIFsgbXhzIF07CnZlY3RvciA8IHBhaXIgPCBpbnQgLCBkb3VibGUgPiA+IGdyYXBoIFsgbXhzIF07CmludCBwICwgcSAsIGEgLCBiICwgbiAsIHQgLCBtICwgYyAsIGsgLCBsb2dfOwpib29sIHZpc2l0ZWQgWyBteHMgXTsKcHJpb3JpdHlfcXVldWUgPCBwYWlyIDwgZG91YmxlICwgaW50ID4gPiBwcTsKZG91YmxlIHggLCB5ICwgeiAsIHcgLCBhbnMgLCBzdW07CnZvaWQgbWFrZV9ncmFwaCgpOwp2b2lkIG1zdCgpOwp2b2lkIGNsZWFyXygpOwp2b2lkIGRmcyggaW50IHNvdXJjZSApOwp2b2lkIG1ha2Vfc3BhcnNlKCk7CnZvaWQgc29sdXRpb25fZmluZGVyKCk7CmRvdWJsZSBsY2EoKTsKaW50IG1haW4oKQp7CiAgICAvL2lvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgLy9jaW4udGllKE5VTEwpOwogICAgc2NhbmYoIiVkIiwmdCk7CiAgICB3aGlsZSAoIHQtLSApCiAgICB7CiAgICAgICAgY2xlYXJfKCk7CiAgICAgICAgc2NhbmYoIiVkIiwmbik7CiAgICAgICAgZm9yICggaW50IGkgPSAxOyBpIDw9IG47IGkrKyApc2NhbmYoIiVsZiVsZiAlZCIsJmxvYyBbIDAgXSBbIGkgXSAsICZsb2MgWyAxIF0gWyBpIF0sICZwb3B1bGF0aW9uIFsgaSBdICk7CiAgICAgICAgbWFrZV9ncmFwaCgpOwogICAgICAgIG1zdCgpOwogICAgICAgIGxldmVsIFsgMSBdID0gMDsKICAgICAgICBwYXJlbnQgWyAxIF0gPSAtMTsKICAgICAgICBjb3N0IFsgMSBdID0gMC4wMDsKICAgICAgICBkZnMoIDEgKTsKICAgICAgICBtYWtlX3NwYXJzZSgpOwogICAgICAgIHNvbHV0aW9uX2ZpbmRlcigpOwogICAgICAgIHByaW50ZigiJS4yZlxuIixhbnMpOwogICAgfQogICAgcmV0dXJuIDA7Cn0Kdm9pZCBjbGVhcl8oKQp7CiAgICAvL21lbXNldCggdmFsdWUgLCAwLjAwLCBzaXplb2YgdmFsdWUgKTsKICAgIG1lbXNldCggc3BhcnNlICwgLTEsIHNpemVvZiBzcGFyc2UgKTsKICAgIGZvciAoIGludCBpID0gMDsgaSA8PSAxMDAyOyBpKysgKQogICAgewogICAgICAgIHZpc2l0ZWQgWyBpIF0gPSAwOwogICAgICAgIGdyYXBoIFsgaSBdLmNsZWFyKCk7CiAgICAgICAgY29zdCBbIGkgXSA9IGluZjsKICAgIH0KfQp2b2lkIG1ha2VfZ3JhcGgoKQp7CiAgICBmb3IgKCBpbnQgaSA9IDE7IGkgPD0gbjsgaSsrICkKICAgIHsKICAgICAgICBmb3IgKCBpbnQgaiA9IDE7IGogPD0gbjsgaisrICkKICAgICAgICB7CiAgICAgICAgICAgIGlmICggaSA9PSBqICljb250aW51ZTsKICAgICAgICAgICAgeCA9IGxvYyBbIDAgXSBbIGkgXSAtIGxvYyBbIDAgXSBbIGogXTsKICAgICAgICAgICAgeCAqPSB4OwogICAgICAgICAgICB5ID0gbG9jIFsgMSBdIFsgaiBdIC0gbG9jIFsgMSBdIFsgaSBdOwogICAgICAgICAgICB5ICo9IHk7CiAgICAgICAgICAgIHggKz0geTsKICAgICAgICAgICAgeCA9IChkb3VibGUpc3FydCggeCApOwogICAgICAgICAgICBncmFwaCBbIGkgXS5wdXNoX2JhY2sgKCB7IGogLCB4IH0gKTsKICAgICAgICAgICAgZ3JhcGggWyBqIF0ucHVzaF9iYWNrICggeyBpICwgeCB9ICk7CiAgICAgICAgfQogICAgfQp9CnZvaWQgbXN0KCkKewogICAgcGFyZW50IFsgMSBdID0gLTE7CiAgICBwcS5wdXNoKCB7IDAuMDAgLCAxIH0gKTsKICAgIGNvc3QgWyAxIF0gPSAwLjAwOwogICAgd2hpbGUgKCAhcHEuZW1wdHkoKSApCiAgICB7CiAgICAgICAgYSA9IHBxLnRvcCgpLnNlY29uZDsKICAgICAgICBwcS5wb3AoKTsKICAgICAgICBpZiAoIHZpc2l0ZWQgWyBhIF0gKWNvbnRpbnVlOwogICAgICAgIHZpc2l0ZWQgWyBhIF0gPSAxOwogICAgICAgIGludCBzeiA9IGdyYXBoIFsgYSBdLnNpemUoKTsKICAgICAgICBmb3IgKCBpbnQgaSA9IDA7IGkgIT0gc3o7IGkrKyApCiAgICAgICAgewogICAgICAgICAgICBiID0gZ3JhcGggWyBhIF0gWyBpIF0uZmlyc3Q7CiAgICAgICAgICAgIHggPSBncmFwaCBbIGEgXSBbIGkgXS5zZWNvbmQ7CiAgICAgICAgICAgIGlmICggIXZpc2l0ZWQgWyBiIF0gJiYgY29zdCBbIGIgXSA+IHggKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcS5wdXNoKCB7IHggLCBiIH0gKTsKICAgICAgICAgICAgICAgIGNvc3QgWyBiIF0gPSB4OwogICAgICAgICAgICAgICAgcGFyZW50IFsgYiBdID0gYTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGZvciAoIGludCBpID0gMDsgaSA8PSBuOyBpKysgKQogICAgewogICAgICAgIGdyYXBoIFsgaSBdLmNsZWFyKCk7CiAgICAgICAgdmlzaXRlZCBbIGkgXSA9IDA7CiAgICB9CiAgICBzdW0gPSAwLjAwOwogICAgZm9yICggaW50IGkgPSAyOyBpIDw9IG47IGkrKyApCiAgICB7CiAgICAgICAgYSA9IHBhcmVudCBbIGkgXTsKICAgICAgICBzdW0gKz0gY29zdCBbIGkgXTsKICAgICAgICBncmFwaCBbIGEgXS5wdXNoX2JhY2sgKCB7IGkgLCBjb3N0IFsgaSBdIH0gKTsKICAgICAgICBncmFwaCBbIGkgXS5wdXNoX2JhY2sgKCB7IGEgLCBjb3N0IFsgaSBdIH0gKTsKICAgICAgICBwYXJlbnQgWyBpIF0gPSAtMTsKICAgIH0KfQp2b2lkIGRmcyggaW50IHNvdXJjZSApCnsKICAgIHZpc2l0ZWQgWyBzb3VyY2UgXSA9IDE7CiAgICBpbnQgc3ogPSBncmFwaCBbIHNvdXJjZSBdLnNpemUoKTsKICAgIGZvciAoIGludCBpID0gMDsgaSAhPSBzejsgaSsrICkKICAgIHsKICAgICAgICBpbnQgbG9sID0gZ3JhcGggWyBzb3VyY2UgXSBbIGkgXS5maXJzdDsKICAgICAgICBpZiAoICF2aXNpdGVkIFsgbG9sIF0gKQogICAgICAgIHsKICAgICAgICAgICAgcGFyZW50IFsgbG9sIF0gPSBzb3VyY2U7CiAgICAgICAgICAgIGxldmVsIFsgbG9sIF0gPSBsZXZlbCBbIHNvdXJjZSBdICsgMTsKICAgICAgICAgICAgY29zdCBbIGxvbCBdID0gZ3JhcGggWyBzb3VyY2UgXSBbIGkgXS5zZWNvbmQ7CiAgICAgICAgICAgIGRmcyggbG9sICk7CiAgICAgICAgfQogICAgfQp9CnZvaWQgbWFrZV9zcGFyc2UoKQp7CiAgICB2YWx1ZSBbIDAgXSBbIDEgXSA9IDAuMDA7CiAgICBmb3IgKCBpbnQgaSA9IDI7IGkgPD0gbjsgaSsrIClzcGFyc2UgWyAwIF0gWyBpIF0gPSBwYXJlbnQgWyBpIF0sdmFsdWUgWyAwIF0gWyBpIF0gPSBjb3N0IFsgaSBdOwogICAgZm9yICggaW50IGogPSAxOyAoIDE8PGogKSA8PSBuIDsgaisrICkKICAgICAgICBmb3IgKCBpbnQgaSA9IDIgOyBpIDw9IG47IGkrKyApCiAgICAgICAgICAgIGlmICggc3BhcnNlIFsgaiAtIDEgXSBbIGkgXSAhPSAtMSApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNwYXJzZSBbIGogXSBbIGkgXSA9IHNwYXJzZSBbIGogLSAxIF0gWyBzcGFyc2UgWyBqIC0gMSBdIFsgaSBdIF07CiAgICAgICAgICAgICAgICB2YWx1ZSBbIGogXSBbIGkgXSA9IG1heCAoIHZhbHVlIFsgaiAtIDEgXSBbIGkgXSAsIHZhbHVlIFsgaiAtIDEgXSBbIHNwYXJzZSBbIGogLSAxIF0gWyBpIF0gXSApOwogICAgICAgICAgICB9Cn0Kdm9pZCBzb2x1dGlvbl9maW5kZXIoKQp7CiAgICBhbnMgPSAwLjAwOwogICAgZm9yICggaW50IGkgPSAxOyBpIDw9IG47IGkrKyApCiAgICAgICAgZm9yICggaW50IGogPSAxOyBqIDw9IG47IGorKyApCiAgICAgICAgewogICAgICAgICAgICBpZiAoIGkgPT0gaiApY29udGludWU7CiAgICAgICAgICAgIHAgPSBpICwgcSA9IGo7CiAgICAgICAgICAgIHcgPSBsY2EoKTsKICAgICAgICAgICAgeCA9ICggZG91YmxlICkoIHBvcHVsYXRpb24gWyBpIF0gKyBwb3B1bGF0aW9uIFsgaiBdICk7CiAgICAgICAgICAgIGFucyA9IG1heCAoIGFucyAsICggZG91YmxlICkoIHggLyAoIHN1bSAtIHcgKSApICk7CiAgICAgICAgfQp9CmRvdWJsZSBsY2EoKQp7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