#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define len(x) (int)(x.size()) #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; bool umin(int& a, int b) { if(b < a) { a = b; return true; } return false; } bool umax(int& a, int b) { if(b > a) { a = b; return true; } return false; } //#ifdef KoRoVa //#define DEBUG for (bool __DEBUG=1;__DEBUG;__DEBUG=0) //#define LOG(...) prnt(#__VA_ARGS__" ::",_VA_ARGS)<<endl //#else //#define DEBUG while(false) //#define LOG(...) if(false) //#endif template <class ...Ts> auto &prnt(Ts ...ts) { return ((cerr << ts << " "), ...); } const int max_n = 2042, inf = 1000111222; const ll linf = 1000111222000111222; vector<int> g[max_n]; ll kek[max_n * max_n]; int used[max_n], timer = 0, mt[max_n * max_n], mx; inline bool dfs (int v) { if (used[v] == timer) { return false; } used[v] = timer; for (int to : g[v]) { if (to <= mx && (mt[to] == -1 || dfs(mt[to]))) { mt[to] = v; return true; } else if(to > mx) break; } return false; } int ord[max_n], gg[max_n]; mt19937 rng(4242); void test_case() { mx = 0; int n; cin >> n; for (int i = 0; i < n; i++) { ord[i] = i; g[i].clear(); } vector<int> a(n); for(auto& x : a) cin >> x; int ind = 0; for(int i = 0; i < n; i++) { for(int j = 1; j <= n; j++) kek[ind++] = j * 1ll * a[i]; } sort(kek, kek + ind); int sz = unique(kek, kek + ind) - kek; for (int i = 0; i < sz; i++) { mt[i] = -1; } for(int i = 0; i < n; i++) { for(int j = 1; j <= n; j++) g[i].pb(lower_bound(kek, kek + sz, j * 1ll * a[i]) - kek); } int l = 0, r = sz; while(l < r) { map<int, int> was; int mid = (l + r) / 2; mx = mid; for(int i = 0; i < sz; i++) { mt[i] = -1; } ++timer; for(int i = 0; i < n; i++) { if(a[i] <= mid && was[a[i]]++ == 0) { mt[lower_bound(kek, kek + sz, a[i]) - kek] = i; gg[i] = timer; } } int ggtimer = timer; shuffle(ord, ord + n, rng); bool ok = true; for(int i = 0; i < n; i++) { timer++; if (gg[ord[i]] == ggtimer) { continue; } if(!dfs(ord[i])) { ok = false; break; } } if(ok) r = mid; else l = mid + 1; } cout << kek[l] << '\n'; } signed main() { // freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); int testcases = 1; cin >> testcases; while(testcases--) test_case(); exit(0); }