#include using namespace std; int main() { int i; int j; int N; int iNo, iM, iS; map m; vector> v; char Tag[ 30 ]; cin >> N; for( i = 0; i < N; i++ ) { cin >> iNo; cin >> iM; cin >> iS; for( j = 0; j < iM; j++ ) { cin >> Tag; m[ Tag ] += iS; } } for( auto x: m ) v.emplace_back( - x.second, x.first ); sort( v.begin(), v.end() ); for( auto x: v ) { if( ++i >= 10 ) break; cout << x.second << " " << - x.first << endl; } return 0; }