#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i < (b); ++i)
#define REP(i,n) rep(i,0,n)
#define sz(v) ((int) (v).size())
#define rs resize
#define all(v) begin(v), end(v)

struct bi_graph {
    int n, m, s; vvi G; vi L, R, d;
    bi_graph(int _n, int _m) : n(_n), m(_m), s(0), G(n), L(n, -1), R(m, n), d(n+1) {}
    void add_edge(int a, int b) {
        G[a].pb(b);
    }
    bool add_vertex(vi &l){
        m++;
        R.pb(n);
        bool pad = false;
        for(ll i = 0; i < l.size(); i++)
        {
            add_edge(l[i],m - 1);
            if(d[l[i]] != LLONG_MAX) {
                pad = true;
                d[n] = min(d[l[i]] + 1, d[n]);
            }
        }
        if(pad){
            REP(i,n) s += L[i] < 0 && dfs(i);
            bfs();
        }
        return pad;
    }
    bool bfs(){
        queue<int> q; d[n] = LLONG_MAX;
        REP(v,n) {
            if (L[v] < 0) d[v] = 0, q.push(v);
            else d[v] = LLONG_MAX;
        }
        while(!q.empty()){
            int v = q.front(); q.pop();
            if(d[v] >= d[n]) continue;
            for(int u : G[v]) if(d[R[u]] == LLONG_MAX)
                d[R[u]] = d[v] + 1, q.push(R[u]);
        }
        return d[n] != LLONG_MAX;
    }
    bool dfs(int v){
        if(v == n) return true;
        for(int u : G[v])
            if(d[R[u]] == d[v] + 1 && dfs(R[u])){
                R[u] = v; L[v] = u; return true;
            }
        d[v] = LLONG_MAX; return false;
    }
    int max_match(){
        while(bfs()) REP(i,n) s += L[i] < 0 && dfs(i);
        return s;
    }
};

ll n;
vi a;
bool test(ll m){
    //Bepaal de interessante
    vi over;
    for(ll i = 0; i < n; i++)
        if(a[i] * n > m)
            over.pb(a[i]);


    //Bepaal alle matches
    map<ll,ll> index;
    vvi buren = vvi(over.size());
    ll nu, r = 0;
    for(ll i = 0; i < over.size(); i++)
        for(ll j = 1; j <= over.size() && over[i] * j <= m; j++) {
            if (index.count(j * over[i]) == 0) {
                index.emplace(j * over[i], r);
                r++;
            }
            nu = index[j * over[i]];
            buren[i].pb(nu);
        }

    //Test het
    bi_graph g = bi_graph(over.size(),r);
    for(ll i = 0; i < over.size(); i++)
        for(ll j : buren[i])
            g.add_edge(i, j);
    return (g.max_match() == over.size());
}
void run(){
    cin >> n;
    a = vi(n);
    for(ll i = 0; i < n; i++)
        cin >> a[i];

    //Bepaal waar we gaan zoeken
    map<ll,ll> gehad;
    vii rij;
    vvi links;
    ll nu;
    ll len = 0;
    for(ll i = 0; i < n; i++)
        for(ll j = 0; j <= n; j++){
            nu = a[i] * j;
            if(gehad.count(nu) == 0){
                gehad.emplace(nu, len);
                rij.pb(make_pair(nu,len));
                len++;
                links.pb(vi());
            }
            nu = gehad[nu];
            links[nu].pb(i);
        }
    sort(all(rij));

    //Doe de binary search
  /*  ll l = -1, r = rij.size(), m;
    while(r - l > 1){
        m = (l+ r) / 2;
        if(test(rij[m]))
            r = m;
        else
            l = m;
    }
    cout << rij[r] << endl;*/

    //Ga lopen
    bi_graph g = bi_graph(n,0);
    g.max_match();
    ll m = 0;
    ll antw;
    for(antw = 0; antw < rij.size() && m < n; antw++){
        if(g.add_vertex(links[rij[antw].y]))
            m++;
    }
    cout << rij[antw].x<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);
    ll t;
    for(cin >> t; t > 0; t--)
        run();
    return 0;
}