#include <bits/stdc++.h> #define int long long #define MULTITEST true using namespace std; vector<vector<int> >g; vector<vector<int>>conn; vector<int>siz,used,used1; bool try_kuhn(int x){ // cout<<x<<' '<<used[x]<<endl; if(used[x]){ return false; } //cout<<x<<endl; used[x]=1; //cout<<g.size()<<' '<<endl; for(int i=0;i<g[x].size();i++){ //cout<<i<<endl; int to = g[x][i]; //cout<<to<<endl; if(siz[to]){ conn[to].push_back(x); siz[to]--; return true; } for(int j=0;j<conn[to].size();j++){ if(try_kuhn(conn[to][j])){ conn[to][j]=x; return true; } } } return false; } void solve () { g.clear(); conn.clear(); siz.clear(); int n; cin>>n; map<int,int>a; for(int i=0;i<n;i++){ int x; cin>>x; a[x]++; } vector<pair<int,int> >b; for(auto i:a){ b.push_back(i); } used1.clear(); used1.resize(b.size()); conn.resize(b.size()); for(int i=0;i<b.size();i++){ siz.push_back(b[i].second); } priority_queue<int> timer; for(auto i:b){ timer.push({-i.first}); } int ans = 0; while(true){ int x = timer.top(); timer.pop(); vector<int>timerok; while(!timer.empty()&&timer.top()==x){ timer.pop(); } g.resize(g.size()+1); for(int i=0;i<b.size();i++){ //cout<<x<<' '<<b[i].first<<' '<<g.size()<<' '<<b.size()<<endl; if(x % b[i].first == 0){ g[g.size()-1].push_back(i); } } used.resize(g.size()); used.assign(g.size(),0); //cout<<42<<endl; bool ok = try_kuhn(g.size()-1); if(ok){ for(auto i:g[g.size()-1]){ if(!used1[i]) timer.push(-b[i].first+x); } } else{ for(auto i:g[g.size()-1]){ used1[i]=1; } } ans+=ok; if(ans==n){ cout<<-x<<'\n'; break; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.precision(30); int T = 1; if (MULTITEST) cin >> T; for (int t = 0; t < T; t ++) solve(); }