//Shopaholic
//記憶體區段錯誤! Segmentation fault (core dumped)
#include<iostream>
using namespace std;
int main()
{
int N,range;
int change=0;
while(cin>>N)
{
for(int c=0;c<N;c+=1)
{
int moneys[1000] = {};
int total =0,counter=0;
cin >> range;
for(int i=0;i<range;i+=1)
{
cin >> moneys[i];
}
for(int i =0;i<range;i+=1)
{
for(int a=i+1;a<=range;a+=1)
{
if(moneys[i]<moneys[a])
{
change = moneys[i];
moneys[i] = moneys[a];
moneys[a] = change;
}
}
}
for(int i=0;i<range;i+=1)
{
counter+=1;
if(range == 1)
{
total += moneys[i];
}
else if(counter % 3 == 0)
{
total += moneys[i];
}
else if (i == range-1 and range % 3 != 0)
{
total += moneys[i];
if(range % 3 == 2)
{
total += moneys[i-1];
}
}
}
cout << total << endl;
}
}
return 0;
}
int moneys[1000] = {};
商品最多有20000個