#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=(b-1);i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define print(x) cout<<#x<<" = "< a, pair b) { if(a.fi==b.fi){ return (a.se < b.se); } else{ return (a.fi > b.fi); } } int main() { ll n; cin>>n; map ma; rep(i,0,n){ ll n1; cin>>n1; ll m,s; cin>>m>>s; rep(j,0,m){ string st; cin>>st; ma[st]+=s; } } vector > v; map::iterator itr = ma.begin(); while(itr!=ma.end()){ string a = (*itr).fi; ll b = (*itr).se; v.pb(mp(b,a)); itr++; } sort(all(v), f); rep(i,0,v.sz){ cout << v[i].se << " " << v[i].fi << endl; } return 0; }