#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) #define pb push_back #define bug puts("==========="); #define REP(i,n) for(int i=0;i pii; #define CHG ch=getchar() #define FRD x=bo=0; for(CHG;ch<'0'||ch>'9';CHG) if(ch=='-')bo=1; #define FR2 for(;ch>='0'&&ch<='9';x=(x<<1)+(x<<3)+ch-'0',CHG); char ch; int bo; inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';} inline void RD(int &x){ FRD FR2 if (bo)x=-x; } inline void RD(ll &x){ FRD FR2 if (bo)x=-x; } inline ll RD(){ ll x; RD(x); return x; } inline void RD(char *s){///scanf %s for (CHG;blank(ch);CHG); for (;!blank(ch);CHG)*s++=ch; *s=0; } inline void RD(char &c){for(CHG;blank(c);CHG);} template inline void OT(T x){ static char buf[20]; char *p1=buf;if (!x)*p1++='0';if (x<0)putchar('-'),x=-x; while(x)*p1++=x%10+'0',x/=10; while(p1--!=buf)putchar(*p1); } inline void pe(){puts("");}//输出回车 inline void pk(){putchar(' ');}//输出空格 const double eps=1e-8; const ll inf=2e9; const int maxn=1e4+70; const ll mod =100000007; /*======================================*/ mapmp; priority_queue q; int ct[110]; int main() { T_T{ int n=RD(); mp.clear(); while(!q.empty())q.pop(); char s[14]; int a; int cnt=1; mem(ct,0); REP(i,n) { scanf("%s %d",s,&a); int k=mp[s]; if(k==0)k=mp[s]=cnt++; q.push(pii(a,k)); } ll ans=0; while(!q.empty()) { pii p=q.top(); q.pop(); int k=p.second; if(ct[k]<2) { ct[k]++; ans+=p.first; } } OT(ans),pe(); } return 0; }