#include <bits/stdc++.h>

#define X first
#define Y second
#define PB push_back
#define x first
#define y second
#define pb push_back
#define all(a) begin(a),end(a)
#define sz(a) (int)(a).size()
#define rep(i,a,b) for (int i=a;i<(b);++i)

using namespace std;

typedef long long ll;
using pii=pair<int,int>;
typedef vector<int> vi;

const int N=2010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

map<int,int> as;
vector<ll> bitni;
vector<pair<ll,ll>> edges;
vector<int> v[N];
int match[N * N], last[N], n, n_r, ptr[N], bio[N], cookie, val[N], A[N];

int dfs(int x) {
	if(bio[x] == cookie) return 0;
	bio[x] = cookie;
	//cout << "dfs " << x << endl;
	for(;ptr[val[x]] <= last[x];ptr[val[x]]++) {
		if(match[v[x][ptr[val[x]]]] == -1) {
			match[v[x][ptr[val[x]]]] = x;
			return 1;
		}
	}
	for(int i = 0;i <= last[x];i++) {
		if(dfs(match[v[x][i]])) {
			match[v[x][i]] = x;
			return 1;
		}
	}
	return 0;
}

bool check(int mid) {
	for(int i = 0;i < n_r;i++) match[i] = -1;
	for(int i = 0;i < n;i++) {
		last[i] = min((ll)n, bitni[mid] / A[i]) - 1; 
		ptr[val[i]] = 0;
	}
	for(int i = 0;i < n;i++) {
		cookie++;
		if(!dfs(i)) return false;
	}
	return true;
}

void solve() {
	as.clear(); bitni.clear(); edges.clear();
	cin >> n;
	for(int i = 0;i < n * n + 10;i++) match[i] = 0;
	for(int i = 0;i < n;i++) v[i].clear();
	vi sazA;
	for(int i = 0;i < n;i++) {
		int x; cin >> x;
		as[x]++; A[i] = x; 
		for(int j = 1;j <= n;j++) {
			bitni.PB((ll)j * x);
			edges.PB({(ll)j * x, i});
		}
	}
	
	ll L = 0;
	vector < pii> as_v;
	
	
	for(auto &[x, cnt] : as) {		
		L = max(L, (ll)x * cnt);
		as_v.PB({x, cnt});
		sazA.PB(x);
	}
	
	for(int i = 0;i < n;i++) 
		val[i] = lower_bound(sazA.begin(), sazA.end(), A[i]) - sazA.begin(); 

	sort(bitni.begin(), bitni.end());
	bitni.erase(unique(bitni.begin(), bitni.end()), bitni.end());
	
	int lo = lower_bound(bitni.begin(), bitni.end(), L) - bitni.begin();
	int hi = (int)bitni.size() - 1;
	
	int tko2 = 0;
	
	sort(edges.begin(), edges.end());
	
	for(auto &[r, l] : edges) {
		while(bitni[tko2] < r) tko2++;
		v[l].PB(tko2);	
	}
	
	n_r = tko2 + 1;	


	while(lo < hi) {
		int mid = (lo + hi) / 2;
		if(check(mid)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	
	cout << bitni[hi] << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int T; cin >> T;
	for(;T--;) solve();
	return 0;
}