#include <bits/stdc++.h> using namespace std; #define vt vector #define ll long long #define rall(x) (x).rbegin(), (x).rend() #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() const char nl = '\n'; template<typename T> ostream& operator << (ostream& os, vector<T> v) { bool f = 1; os << "["; for(auto x : v) { if(!f) os << ", "; os << x; f = 0; } return os << "]"; } void solve() { int N; cin >> N; vt<ll> v(N); for(auto& x : v) cin >> x; vector<ll> all_times; for(auto x : v) { for(int i = 1; i <= N; i++) { all_times.push_back(i * x); } } sort(all(all_times)); all_times.erase(unique(all(all_times)), all_times.end()); int S = N + sz(all_times); vt<vt<int>> g(S); int new_idx = N; auto add_time = [&](ll t) { for(int i = 0; i < N; i++) { if(t % v[i] == 0) { g[i].push_back(new_idx); g[new_idx].push_back(i); } } new_idx++; }; vt<bool> vis(N); vt<int> nei(N, -1); function<bool(int)> dfs = [&](int u) { if(nei[u] == -1) return true; vis[u] = true; int x = nei[u]; for(int v : g[x]) { if(!vis[v] && dfs(v)) { nei[v] = x; return true; } } return false; }; for(int i = 0; i < N; i++) add_time(all_times[i]); for(int i = 0; i < sz(all_times); i++) { if(i >= N) add_time(all_times[i]); vis = vt<bool>(N, false); int me = i + N; for(int x : g[me]) { if(dfs(x)) { nei[x] = me; break; } } if(count(all(nei), -1) == 0) { cout << all_times[i] << nl; return; } } assert(false); } int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while(T--) { solve(); } }