#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int main() { int N, No, M, S; cin >> N; map mp; for (int i = 0; i < N; i++) { cin >> No >> M >> S; for (int j = 0; j < M; j++) { string tag; cin >> tag; mp[tag] += S; } } vector> vec; for (auto p: mp) { vec.push_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; }