#include #include #include #include #include #include #include #include #define rep(N) for (int i = 0; i < N; i++) #define For(i, N) for (i = 0; i < N; i++) #define re return 0 using namespace std; using ll = long long int; using vi = vector; using vvi = vector>; using vs = vector; using pii = pair; using pis = pair; bool comp(pis A, pis B) { if (A.first != B.first)return A.first > B.first; else return A.second < B.second; } int main() { int N, No; vector G; cin >> N; rep(N) { int M, S; cin >> No >> M >> S; rep(M) { bool flag = true; string s; cin >> s; rep(G.size()) { if (G[i].second == s) { G[i].first += S; flag = false; } } if (flag) G.push_back({ S,s }); } } sort(G.begin(), G.end(), comp); for (int i = 0; i < 10 && i < G.size(); ++i) cout << G[i].second << " " << G[i].first << endl; re; }