#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N; map mp; while(N--){ int z; cin >> z; int M,S; cin >> M >> S; rep(i,M){ string s; cin >> s; mp[s]+=S; } } vector> V; for(auto m:mp){ V.pb({-m.second,m.first}); } sort(all(V)); rep(i,min(10,sz(V))){ cout << V[i].second << ' ' << abs(V[i].first) << endl; } return 0; }