#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int32_t n; cin >> n; unordered_map hist; for (auto i = 0; i < n; ++i) { int32_t no, m, s; cin >> no >> m >> s; for (auto j = 0; j < m; ++j) { string t; cin >> t; hist[t] += s; } } vector> ans; for (auto &&p : hist) { ans.push_back({-p.second, p.first}); } sort(ans.begin(), ans.end()); for (auto i = 0; i < min(ans.size(), size_t(10)); ++i) { cout << ans[i].second << " " << -ans[i].first << endl; } return 0; }