#include using namespace std; struct Pair { int a; string s; bool operator < ( const Pair &X ) const { return a == X.a ? s < X.s : a < X.a; } }; int main() { int i; int j; int N; int M; int S; string Tag; map Mp; vector V; ios::sync_with_stdio( false ); cin.tie( 0 ); cin >> N; for( i = 0; i < N; i++ ) { cin >> M; //cin >> No; cin >> M; cin >> S; for( j = 0; j < M; j++ ) { cin >> Tag; Mp[ Tag ] += S; } } for( auto &p : Mp ) V.emplace_back( Pair { - p.second, p.first } ); sort( V.begin(), V.end() ); M = min( (int) V.size(), 10 ); for( i = 0; i < M; i++ ) cout << V[ i ].s << " " << - V[ i ].a << endl; return 0; }