#include using namespace std; bool cmp(const pair &a, const pair &b) { if (a.first != b.first) return a.first > b.first; else return a.second < b.second; } int main() { int n; cin >> n; map mp; for (int i = 0; i < n; ++i) { int no, m, s; cin >> no >> m >> s; for (int j = 0; j < m; ++j) { string tag; cin >> tag; mp[tag] += s; } } vector> vt; for (const auto &au : mp) { vt.emplace_back(au.second, au.first); } sort(vt.begin(), vt.end(), cmp); for (int i = 0; i < min(10, (int) vt.size()); ++i) { cout << vt[i].second << " " << vt[i].first << endl; } return 0; }