#include typedef long long ll; using namespace std; int INF = 1LL << 30; int MOD = 1e9+7; bool comp(const pair &a,const pair &b){ if(a.second == b.second)return a.first < b.first; return a.second > b.second; } main(){ int N; cin >> N; map mp; for(int i = 0;i < N;i++){ int a,b,c; cin >> a >> b >> c; for(int j = 0;j < b;j++){ string s; cin >> s; mp[s] += c; } } vector >V; for(auto p:mp){ V.push_back(p); } sort(V.begin(), V.end(), comp); for(int i = 0;i < min((int)V.size(), 10);i++){ cout << V[i].first << " " << V[i].second << endl; } }