#include using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define pb push_back #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() #define fi first #define se second typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; const int INF = 1e9; const ll MOD = 1e9 + 7; double EPS = 1e-8; vector split(const string& s, char c = ' ') { vector ret; stringstream ss(s); string t; while(getline(ss, t, c)) ret.push_back(t); return ret; } int main(){ int n; cin >> n; map mp; rep(i, n) { int _, m, s; cin >> _ >> m >> s; string t; rep(i, m) { cin >> t; mp[t] += s; } } using P = pair; priority_queue,greater

> q; for(auto& p : mp) q.push({-p.se, p.fi}); rep(i, 10) { if(q.empty()) break; auto p = q.top(); q.pop(); cout << p.se << " " << - p.fi << endl; } return 0; }