#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()

bool dfs(int a, int L, vector<vi>& g, vi& btoa, vi& A, vi& B, ll k) {
    if (A[a] != L) return 0;
    A[a] = -1;
    for (int b : g[a]) {
        if (b >= k) break;
        if (B[b] == L + 1) {
            B[b] = 0;
            if (btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B, k))
                return btoa[b] = a, 1;
        }
    }
    return 0;
}

int hopcroftKarp(vector<vi>& g, vi& btoa, ll k) {
    int res = 0;
    vi A(g.size()), B(btoa.size()), 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 (b >= k) break;
                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, k);
    }
}

ll solve() {
    ll n;
    cin >> n;
    set<ll> forbidden;
    vi a;
    rep(i,0,n) {
        ll x;
        cin >> x;
        if (forbidden.contains(x)) a.push_back(x);
        forbidden.insert(x);
    }
    ranges::sort(a);
    vi relevant;
    vvi adj(size(a));
    for (auto x : a) {
        rep(i, 1, n + 1) {
            if (forbidden.contains(i * x)) continue;
            relevant.push_back(i * x);
        }
    }
    ranges::sort(relevant);
    relevant.erase(unique(all(relevant)), end(relevant));
    for (int j = -1; auto x : a) {
        j++;
        rep(i, 1, n + 1) {
            if (forbidden.contains(i * x)) continue;
            adj[j].push_back(lower_bound(all(relevant), i * x) - begin(relevant));
        }
    }
    if (empty(relevant)) return *rbegin(forbidden);
    ll z = *ranges::partition_point(views::iota(0ll, (ll) size(relevant)), [&] (ll k) {
        vi btoa(k, -1);
        return hopcroftKarp(adj, btoa, k) < size(a);
    });
    assert(z);
    return max(*rbegin(forbidden), relevant[z - 1]);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    cout << setprecision(9) << fixed;

    int t;
    cin >> t;
    while (t--)
        cout << solve() << '\n';
}