#include using namespace std; typedef long long ll; const int maxn = 1000 + 10; int a[maxn][5]; map mp; char str[maxn][55]; int main(){ int T; scanf("%d",&T); while(T--){ int n,tot=1; scanf("%d",&n); memset(a,0,sizeof(a)); for(int i=0 ;i a[id][0]) a[id][0] = v; else if(v > a[id][1]) a[id][1] = v; if(a[id][0] > a[id][1]) swap(a[id][0],a[id][1]); } ll ans = 0; for(int i=1 ;i