#include using namespace std; using ll=long long; using pl=pair; struct UnionFind { vector data; UnionFind(int size) : data(size, -1) { } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t>0){ t--; ll n; cin >> n; vector a(n); vector pos,neg,zero; for(ll i=0;i> a[i].first; a[i].second=i; if(a[i].first>0){pos.push_back(a[i]);} else if(a[i].first<0){neg.push_back(a[i]);} else{zero.push_back(a[i]);} } sort(pos.begin(),pos.end()); sort(neg.begin(),neg.end()); vector> eg; for(ll i=0;i0){ eg.push_back({pos[0].first*a[i].first,{pos[0].second,a[i].second}}); eg.push_back({pos.back().first*a[i].first,{pos.back().second,a[i].second}}); } if(neg.size()>0){ eg.push_back({neg[0].first*a[i].first,{neg[0].second,a[i].second}}); eg.push_back({neg.back().first*a[i].first,{neg.back().second,a[i].second}}); } if(zero.size()>0){ eg.push_back({zero[0].first*a[i].first,{zero[0].second,a[i].second}}); } } sort(eg.rbegin(),eg.rend()); UnionFind uf(n); for(auto &nx : eg){ // cout << nx.second.first << " " << nx.second.second << "\n"; uf.unionSet(nx.second.first,nx.second.second); if(uf.size(0)==n){ cout << nx.first << "\n"; break; } } } return 0; }