#include using namespace std; typedef long long ll; int main() { int n; cin>>n; map mp; for (int i = 0; i < n; i++) { int no, m, s; cin >> no >> m >> s; for (int j = 0; j < m; j++) { string t; cin >> t; mp[t] += s; } } int m = mp.size(); pair p[m]; auto it = mp.begin(); for (int i = 0; i < m; i++) { p[i] = { -(*it).second, (*it).first }; it = next(it, 1); } sort(p, p+m); for (int i = 0; i < min(10, m); i++) cout << p[i].second << ' ' << -p[i].first << endl; return 0; }