#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef basic_string<int> vi;
typedef vector<basic_string<int>> 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 dfs(int a, int L, vector<vi>& g, vi& btoa, vi& A, vi& B){
    if (A[a] != L) return 0;
    A[a] = -1;
    for(int b : g[a]) if (B[b] == L+1){
        B[b] = 0;
        if (btoa[b]==-1 || dfs(btoa[b],L+1,g,btoa,A,B))
            return btoa[b]=a,1;
        
    }
    return 0;
}
int hopcroftKarp(vector<vi>& g,vi& btoa) {
    int res=0;
    vi A(g.size(),0),B(btoa.size(),0),cur,next;
    for(;;) {
        fill(all(A),0);
        fill(all(B),0);
        cur.clear();
        for(int a:btoa) if(a!=-1) A[a]=-1;
        rep(a,0,sz(g)) if(A[a]==0) cur.push_back(a);
        for(int lay=1;;lay++) {
            bool islast=0;
            next.clear();
            for(int a:cur) for(int b:g[a]) {
                if (btoa[b]==-1) {
                    B[b] = lay;
                    islast=1;
                }
                else if(btoa[b]!=a&&!B[b]) {
                    B[b]=lay;
                    next.push_back(btoa[b]);
                }
            }
            if(islast) break;
            if (next.empty()) return res;
            for(int a:next) A[a]=lay;
            cur.swap(next);
        }
        rep(a,0,sz(g))
            res +=dfs(a,0,g,btoa,A,B);
    }
}
mt19937 rng(69);

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for(auto& i : a) cin >> i;
    sort(all(a));
    // reverse(all(a));
    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();

     auto get = [&](ll coord) -> int {
        return lower_bound(all(mult),coord)-begin(mult);
     };

    vector<int> countmult(m);
    for(auto& i : a){
        for(ll j=1;j<=n;++j) {
            countmult[get(j*i)] ++;
        }
    }

    vi maxi(n,n+1);
    for(int iter=0;iter<70;++iter) {
    for(int id=0;auto& i : a){
        for(ll j=1;j<=n;++j) {
            
            if (countmult[get(j*i)] == 1){
                for(int o=j+1;o<maxi[id];++o) {
                    countmult[get(ll(o)*i)]--;
                }
                maxi[id]=j+1;
                break;
            }
        }
        id++;
    }
    }
    vector<ll> nmult;
    for(auto x : mult) {
        if(countmult[get(x)]!=0) nmult.push_back(x);
    }
    swap(nmult,mult);
    m = mult.size();

    int lo=0,hi = m-1;
    while(lo<hi) {
        int mid = (lo+hi)/2;
        vvi g(n);
        for(int i=0;i<n;++i) {
            for(ll j=1;j<maxi[i];++j) {
                int who = lower_bound(all(mult),a[i]*j)-mult.begin();
                if(who<=mid) g[i].push_back(who);
            }
        }
        // for(auto& i : g) reverse(all(i));
        vi btoa(mid+1,-1);
        int res = hopcroftKarp(g,btoa);
        if(res!=n) {
            lo = mid+1;
        } else {
            hi = mid;
        }
    }
    cout << mult[lo] << '\n';
}

int main() {
    cin.tie(NULL);
    cin.sync_with_stdio(false);
    int t; cin >> t;
    while(t--) solve();
}