#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long long, long long> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const long long N = 2005;
const long long M = N * N;
vector<long long> T[N];

map<ll, long long> idx;

long long mt[M], ind[M];
bool used[M];

bool kuhn(long long u)
{
    if(used[u])
        return 0;
    used[u]=1;
    for(auto v: T[u])
    {
        if(mt[v]==-1||kuhn(mt[v]))
        {
            mt[v]=u;
            ind[u]=v;
            return 1;
        }
    }
    return 0;
}

long long n, m;
vector<ll> a;
bool can(long long mid){
    for(long long i = 0 ; i < n; i ++ ){
       T[i].clear(); 
    }
    for(long long i = 0 ; i < n; i ++ ){
        for(long long x = 1; x <= n; x ++ ){
            ll nx = a[i] * 1ll * x;
            long long ni = idx[nx];
            if(ni <= mid){
                T[i].push_back(ni);
            }
        }
    }
    for(long long i = 0 ; i < m ; i ++ ){
        mt[i] = -1;
    }
    for(long long i = 0 ; i < n; i ++ ){
        ind[i] = -1;
    }
    for(long long run = 1; run;){
        run=0;
        for(long long i = 0 ; i < n; i ++ ){
            used[i] = 0;
        }
        for(long long i = 0 ; i < n ; i ++ ){
            if(ind[i] == -1 && kuhn(i)){
                run = 1;
            }
        }
    }
    for(long long i = 0 ; i < n; i ++ ){
        if(ind[i] == -1) return false;
    }
    return true;
}

void solve(){
    idx.clear();
    a.clear();
    cin >> n;
    a.resize(n);
    vector<ll> e;
    for(long long i = 0 ; i < n; i ++ ){
        cin >> a[i];
        for(long long j = 1; j <= n; j ++ ){
            e.push_back(a[i] * 1ll * j);
        }
    }
    sort(e.begin(), e.end());
    e.resize(unique(e.begin(), e.end()) - e.begin());
    for(long long i = 0 ; i < e.size(); i ++ ){
        idx[e[i]] = i;
    }
    m = e.size();
    long long l = 0;
    long long r = m - 1;
    while(l < r){
        long long mid = (l + r) / 2;
        if(can(mid)){
            r = mid;
        }
        else{
            l = mid + 1;
        }
    }
    cout << e[l] << "\n";
}

int main(){
    fastIO;
    long long tc;
    cin >> tc;
    for(long long iq = 1; iq <= tc; iq ++ ){
        solve();
    }
    return 0;
}