/*=============================================================== Author: haotian Created Time : 2017年02月25日 星期六 20时20分41秒 File Name: ./a.cpp ================================================================*/ #include #include #include #include #include #include #include #include #include #define LL long long using namespace std; const int maxN=107; struct node{ char s[13]; int v; bool operator < (const node & t) const { if (strcmp(s,t.s)==0) return v>t.v; return strcmp(s,t.s)<0; } }a[maxN]; int main(){ int T; scanf("%d",&T); while (T--){ int N; scanf("%d",&N); for (int i=1;i<=N;i++) scanf("%s %d",a[i].s,&a[i].v); sort(a+1,a+N+1); int ans=0; bool flag=0; for (int i=1;i<=N;i++) { if (strcmp(a[i].s,a[i-1].s)==0) { if (!flag){ ans+=a[i].v; flag=true; } } else { ans+=a[i].v; flag=false; } } printf("%d\n",ans); } return 0; }