#include <bits/stdc++.h>
using namespace std;
bool comp(int a,int b)
{
return a > b;
}
int main() {
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
int A[N];
for(int i=0;i<N;i++)
{
cin>>A[i];
}
while(true)
{
sort(A,A+N,comp);
int i=0;
int flag =0;
while(A[i] > 2*A[N])
{
i++;
}
cout<<"i="<<i<<endl;
if(A[i] <= 2*A[N] && A[i] > A[N])
{
int temp = A[i];
A[i] = A[N];
A[N] = temp;
flag=1;
}
for(int j=0;j<=N;j++)
{
cout<<"A["<<j<<"]="<<A[j]<<endl;
}
if(flag == 0)
{
break;
}
}
int sum=0;
for(int i=0;i<N;i++)
{
sum+=A[i];
}
cout<<sum<<endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpib29sIGNvbXAoaW50IGEsaW50IGIpCnsKICAgIHJldHVybiBhID4gYjsKfQoKaW50IG1haW4oKSB7CglpbnQgVDsKCWNpbj4+VDsKCQoJCgl3aGlsZShULS0pCgl7CgkgICAgaW50IE47CgkgICAgY2luPj5OOwoJICAgIAoJICAgIGludCBBW05dOwoJICAgIGZvcihpbnQgaT0wO2k8TjtpKyspCgkgICAgewoJICAgICAgICBjaW4+PkFbaV07CgkgICAgfQoJICAgIAoJICAgIHdoaWxlKHRydWUpCgkgICAgewoJICAgICAgICBzb3J0KEEsQStOLGNvbXApOwogICAgCSAgICBpbnQgaT0wOwogICAgCSAgICBpbnQgZmxhZyA9MDsKICAgIAkgICAgd2hpbGUoQVtpXSA+IDIqQVtOXSkKICAgIAkgICAgewogICAgCSAgICAgICAgaSsrOwogICAgCSAgICB9CiAgICAJICAgIAogICAgCSAgICBjb3V0PDwiaT0iPDxpPDxlbmRsOwogICAgCSAgICBpZihBW2ldIDw9IDIqQVtOXSAmJiBBW2ldID4gQVtOXSkKICAgIAkgICAgewogICAgCSAgICAgICAgaW50IHRlbXAgPSBBW2ldOwogICAgCSAgICAgICAgQVtpXSA9IEFbTl07CiAgICAJICAgICAgICBBW05dID0gdGVtcDsKICAgIAkgICAgICAgIGZsYWc9MTsKICAgIAkgICAgfQogICAgCSAgICBmb3IoaW50IGo9MDtqPD1OO2orKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY291dDw8IkFbIjw8ajw8Il09Ijw8QVtqXTw8ZW5kbDsKICAgICAgICAgICAgfQogICAgCSAgICAKICAgIAkgICAgaWYoZmxhZyA9PSAwKQogICAgCSAgICB7CiAgICAJICAgICAgICBicmVhazsKICAgIAkgICAgfQoJICAgIH0KCSAgICAKCSAgICBpbnQgc3VtPTA7CgkgICAgZm9yKGludCBpPTA7aTxOO2krKykKICAgICAgICB7CiAgICAgICAgICAgIHN1bSs9QVtpXTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgY291dDw8c3VtPDxlbmRsOwoJfQoKfQo=