#include #include #include #include #include using namespace std; int main() { map mp; int N, t, point, M; cin >> N; for (int k = 0; k < N; k++) { cin >> M >> t >> point; for (int i = 0; i < t; i++) { string str; cin >> str; mp[str] += point; } } vector> vec; for(auto x : mp) vec.push_back({-x.second, x.first}); sort(vec.begin(), vec.end()); int cnt = min(10, (int)vec.size()); for(int i = 0; i < cnt; i++) { cout << vec[i].second << " " << -vec[i].first << endl; } return 0; }