#include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define all(a) a.begin(),a.end() #define pointtype double #define pointtype_INT 0 using namespace std; typedef long long LL; typedef pairpii; typedef unsigned uint; typedef unsigned long long uLL; const double pi=acos(-1); template void Read(T &x){ char c; bool f(0); while(c=getchar(),c!=EOF){ if(c=='-') f=1; else if(c>='0'&&c<='9'){ x=c-'0'; while(c=getchar(),c>='0'&&c<='9') x=x*10+c-'0'; ungetc(c,stdin); if(f) x=-x; return; } } } struct point{ pointtype x,y; inline point(){ } inline point(pointtype x,pointtype y=0):x(x),y(y){ } inline point operator+(const point &a)const{ return point(x+a.x,y+a.y); } inline point operator+=(const point &a){ return *this=*this+a; } inline point operator-(const point &a)const{ return point(x-a.x,y-a.y); } inline point operator-=(const point &a){ return *this=*this-a; } inline bool operator<(const point &b)const{ if(x==b.x) return y struct hashnode{ T val; T2 v; hashnode *next; }; template inline int& addhash(int u,const T &val,T2 *&ecnt,T2 **adj){ T2 *p=++ecnt; p->val=val; p->v=0; p->next=adj[u]; adj[u]=p; return p->v; } template class hash_table{ hashnode*adj[MOD],edge[ss+10],*ecnt; int sz; public: inline int Get_val(int x){ return x%MOD; } #if pointtype_INT==1 inline int Get_val(point x){ return (x.x*998244353ll+x.y)%MOD; } #endif inline hash_table():ecnt(edge),sz(0){ for(int i=0;i* hash(const T &x){ int t=Get_val(x); for(hashnode *p=adj[t];p;p=p->next) if(p->val==x) return p; return 0; } inline int &operator[](const T &x){ hashnode *p=hash(x); if(p) return p->v; return ++sz,addhash(Get_val(x)%MOD,x,ecnt,adj); } inline bool count(const T &x){ return hash(x); } inline void clear(){ ecnt=edge; int t=MOD>>2<<2,i; for(i=0;i struct Matrix{ int a[sz][sz]; inline Matrix(){ memset(a,0,sizeof a); } inline Matrix(int){ memset(a,0,sizeof a); for(int i=0;i>=1; } return ret; } }; template struct polynomial{ T a[len]; inline void clear(){ int t=len>>2<<2,i; for(i=0;i>2<<2,i; for(i=0;i>2<<2,i; for(i=0;ia; int T,n,ans; char ss[20]; int main() { Read(T); int b; while(T--){ Read(n); a.clear(); while(n--){ scanf("%s",ss); s=ss; Read(b); if(b>a[s].first){ a[s].second=a[s].first; a[s].first=b; } else if(b>a[s].second) a[s].second=b; } ans=0; for(auto &i:a){ ans+=i.second.first+i.second.second; } printf("%d\n",ans); } }