#include using namespace std; typedef long long ll; struct tag { int p; string t; tag() {} tag(int p_, string t_): p(p_), t(t_) {} bool operator<(const tag& rh) const { if (rh.p == p) { return t > rh.t; } return p < rh.p; } }; int main() { int n; cin >> n; map mp; for (int i = 0; i < n; ++i) { int id; cin >> id; int m, p; cin >> m >> p; for (int j = 0; j < m; ++j) { string s; cin >> s; mp[s] += p; } } vector tags; for (auto const &e: mp) { tags.emplace_back(e.second, e.first); } sort(tags.rbegin(), tags.rend()); int cnt = 0; for (tag const &tg: tags) { if (cnt == 10) break; cout << tg.t << " " << tg.p << '\n'; cnt++; } return 0; }