#include #include #include #include #include using namespace std; int main() { int N; cin >> N; map mp; for (int i = 0; i < N; i++) { int No; cin >> No; int M, S; cin >> M >> S; for (int j = 0; j < M; j++) { string tag; cin >> tag; mp[tag] += S; } } vector> vec; for (auto p : mp) { vec.emplace_back(-p.second, p.first); } sort(vec.begin(), vec.end()); for (int i = 0; i < min(10, (int)vec.size()); i++) { cout << vec[i].second << " " << -vec[i].first << endl; } return 0; }