#include #include #include #include #include #include using namespace std; int main() { int t,n,val,i,j,si,ans; string s; set st; map mp; vector v[105]; cin>>t; while(t--) { st.clear(); i=0; ans=0; cin>>n; while(n--) { cin>>s>>val; if(st.count(s)==0) { st.insert(s); mp[s]=i++; } v[mp[s]].push_back(val); } for(j=0;j