#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <functional>
#include <map>
#include <algorithm>
using namespace std;
using pd = pair<double,int>;
using ll = long long;

void solve(){
	int n;
	cin >> n;
	vector<ll> v(n);
	map<ll, ll> m;
	set<ll> s;
	for(auto &x: v)cin >> x;
	for(auto x: v)++m[-x];
	for (auto [k, v]: m){
		ll x = -k;
		ll c=x;
		for(int i = 0; i < v; ++i){
			while(s.count(c))c += x;
			s.insert(c);
		}
	}
	cout << *prev(s.end()) << endl;
}

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