#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 2e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout< b.second; } } }; int main() { int n0; cin >> n0; set st; map mp; for (int unko = 0; unko < n0; unko++) { int n; cin >> n; int m, s; cin >> m >> s; for (int i = 0; i < m; i++) { string tag; cin >> tag; mp[tag] += s; st.insert(tag); } } priority_queue, Cmp> pq; for (auto itr = st.begin(); itr != st.end(); itr++) { string tag = *itr; int score = mp[tag]; pq.push(make_pair(score, tag)); } for (int i = 0; i < 10; i++) { auto a = pq.top(); cout << a.second << " " << a.first << endl; pq.pop(); if (pq.empty()) { return 0; } } }