#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N; map pt; vector > is; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N) { int no, M, S; cin >> no >> M >> S; rep(j, M) { string t; cin >> t; pt[t] += S; } } each(p, pt) { is.emplace_back(-p.second, p.first); } sort(all(is)); rep(i, min(10, sz(is))) { cout << is[i].second << ' ' << -is[i].first << endl; } }