#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef basic_string<short> vi; typedef vector<basic_string<short>> vvi; #define all(x) begin(x),end(x) #define rep(i,a,b) for(int i=(a);i<(b);++i) #define sz(x) int(x.size()) int T=0; bool find(int j, vvi& g, vi& btoa, vi& vis) { if(btoa[j]==-1) return 1; vis[j]=T; int di = btoa[j]; for(int e : g[di]) if(vis[e]!=T && find(e,g,btoa,vis)) { btoa[e]=di; return 1; } return 0; } int dfsMatching(vvi& g, vi& btoa) { vi vis(sz(btoa),0); int ans=0; rep(i,0,sz(g)) { T++; for(int j : g[i]) if(find(j,g,btoa,vis)) { btoa[j]=i; ans++; break; } if(ans==sz(btoa)) return i; } return -1; } mt19937 rng(69); void solve() { int n; cin >> n; vector<int> a(n); for(auto& i : a) cin >> i; vector<ll> mult; for(auto& i : a) { for(ll j=1;j<=n;++j) { mult.push_back(j*i); } } sort(all(mult)); mult.erase(unique(all(mult)),mult.end()); int m = mult.size(); vvi g(m); for(int i=0;i<n;++i) { for(ll j=1;j<=n;++j) { int who = lower_bound(all(mult),a[i]*j)-mult.begin(); g[who].push_back(i); } } for(auto& v : g) { shuffle(all(v),rng); } vi btoa(n,-1); int res = dfsMatching(g,btoa); cout << mult[res] << '\n'; } int main() { cin.tie(NULL); cin.sync_with_stdio(false); int t; cin >> t; while(t--) solve(); }