#include using namespace std; 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 Tag; cin >> Tag; mp[Tag] += S; } } vector> v; for( auto e : mp ) { v.push_back( make_pair( e.second, e.first ) ); } sort( v.begin(), v.end(), greater>() ); vector vv; int last = -1; for( int i = 0; i < v.size(); i++ ) { if( v[i].first != last ) { vv.push_back( v[i].first ); last = v[i].first; } } vector> vs( (int)vv.size() ); int idx = 0; for( int i = 0; i < v.size(); i++ ) { if( v[i].first != vv[idx] ) idx++; vs[idx].push_back( v[i].second ); } for( int i = 0; i < vv.size(); i++ ) { sort( vs[i].begin(), vs[i].end() ); } int n = 0; for( int i = 0; i < vv.size(); i++ ) { for( int j = 0; j < vs[i].size(); j++ ) { cout << vs[i][j] << " " << vv[i] << endl; n++; if( n >= 10 ) return 0; } } }