#include #include "bits/stdc++.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; const int INF = 1e8; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) using namespace std; typedef pair P; struct tag_value { string s; int v; }; vector ans; bool comp(const tag_value& a, const tag_value& b) { return a.v == b.v ? a.s < b.s : a.v > b.v; } map web_tast; int main() { int n = 0; cin >> n; int tag = 0, score = 0; tag_value tv; for (int i = 0; i < n; i++) { cin >> tag; cin >> tag >> score; string s; for (int j = 0; j < tag; j++) { cin >> s; web_tast[s] += score; } } map::iterator itr; for (itr = web_tast.begin(); itr != web_tast.end(); ++itr) { tv.s = itr->first; tv.v = itr->second; ans.push_back(tv); } sort(ans.begin(), ans.end(), comp); int ct = ans.size(); if (ct > 10) { for (int i = 0; i < 10; i++) { tv = ans[i]; cout << tv.s << " " << tv.v << endl; } } else { for (int i = 0; i < ans.size(); i++) { tv = ans[i]; cout << tv.s << " " << tv.v << endl; } } return 0; }