#include using namespace std; #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for(ll i=0; i<(ll)(n); i++) int lob(const auto& v, auto x) { return lower_bound(ALL(v),x)-v.begin(); } bool chmax(auto& a, auto b) { return ab ? a=b, true : false; } using ll=long long; const int INF=1e9+10; const ll INFL=4e18; using VI=vector; using VVI=vector; using VL=vector; using VVL=vector; using PL=pair; using VP=vector; using WG=vector>>; #ifdef LOCAL #include "./debug.hpp" #else #define debug(...) #define print_line #endif //---------------------------------------------------------- void solve() { ll N; cin>>N; VL A(N); REP(i,N) cin>>A[i]; int mx=1e6; VI lpf(mx+1,INF); for(int i=2; i<=mx; i++) { if(lpf[i]==INF) { for(int j=i; j<=mx; j+=i) lpf[j]=i; } } sort(ALL(A)); VVL muls(mx+1); REP(i,N) { ll a=A[i]; while(a>1) { ll p=lpf[a]; while(a%p==0) a/=p; muls[p].push_back(i); } } ll sum=reduce(ALL(A)); ll ans=INFL; multiset ms(ALL(A)); for(int p=2; p<=mx; p++) if(lpf[p]==p) { ll res=sum; ll mx=0; for(int i: muls[p]) { res-=A[i]; ms.erase(ms.find(A[i])); ll a=A[i]; while(a%p==0) a/=p; if(a>1) res+=a; if(a>1) chmax(mx,a); } if(ms.size()) chmax(mx,*ms.rbegin()); for(int i: muls[p]) ms.insert(A[i]); res-=mx; chmin(ans,res); } cout<>T; while(T--) solve(); }