#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using ll=long long;
using ff=double;
int main(void){
IOS;
ll T;
cin>>T;
while(T--){
ll n;
cin>>n;
ll a[n+10];
for(ll i=0;i<n;i++){
cin>>a[i];
}
sort(a, a+n);
ll cost=0, now=0, last=0, ans=0;
ll i=0;
while(a[i]<=abs(cost)){
now=a[i]+last;
// cout<<a[i]<<' '<<last<<' '<<now<<'\n';
ans=now;
last+=now;
cost+=now;
i++;
}
if(i!=n) ans=0;
for(;i<n;i++){
ans+=a[i]+cost;
}
cout<<ans<<'\n';
}
return 0;
}