#include #include #include #include #include #include #include #define LL long long using namespace std; maphas; int val[111][2]; int T_T; char str[15]; int v; int n; int main(void) { // freopen("in.txt","r",stdin); scanf("%d",&T_T); int tot; while (T_T--) { has.clear(); memset(val,0,sizeof(val)); tot = 0; int cnt = 0; scanf("%d",&n); for (int i=0;i= val[a][0]) { tot += v - val[a][1]; val[a][1] = val[a][0]; val[a][0] = v; } else if (v >= val[a][1]) { tot += v - val[a][1]; val[a][1] = v; } } else { has[str] = cnt; val[cnt][0] = v; tot += v; cnt++; } } printf("%d\n",tot); } return 0; }