#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map mp; REP (i, n) { int no; cin >> no; int m, s; cin >> m >> s; REP (i, m) { string tag; cin >> tag; mp[tag] += s; } } vector > vs; for (auto &pr: mp) { vs.push_back({-pr.second, pr.first}); } sort(vs.begin(), vs.end()); for (int i = 0; i < min(10, vs.size()); i++) cout << vs[i].second << " " << -vs[i].first << endl; return 0; }