#include #define rep(i,a,b) for(int i=a;i<(b);++i) #define erep(i,a,b) for(int i=a;i<=(int)(b);++i) #define per(i,a,b) for(int i=(a);i>(b);--i) #define eper(i,a,b) for(int i=(a);i>=b;--i) #define pb push_back #define mp make_pair #define INF 100100100100 #define MOD 1000000007 #define ALL(x) begin(x),end(x) using namespace std; typedef long long ll; typedef pair Pii; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b& fi, const pair& se) { return fi.second > se.second; } int n; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; map rank; rep(i, 0, n) { int ni, m, s; cin >> ni >> m >> s; rep(j, 0, m) { string label; cin >> label; rank[label]+=s; } } vector > a; for (auto x : rank) { a.pb(mp(-x.second, x.first)); } sort(ALL(a)); rep(i, 0, min((int)a.size(), 10)) { cout << a[i].second << " " << -a[i].first << endl; } return 0; }