#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define F first
#define S second

void solve() {
	int n; cin >> n;
	set<int> hv;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = n - 1; i >= 0; i--) {
		int curr = a[i];
		while (hv.count(curr) > 0) {
			curr += a[i];
		}
		hv.insert(curr);
	}
	cout << *hv.rbegin() << "\n";
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t; cin >> t;
	while (t--) solve();
}