#include using namespace std; template T gcd(T x, T y) { if (y == 0) return x; return gcd(y, x % y); } template T lcm(T x, T y) { if (x == 0 || y == 0) return 0; return x / gcd(x, y) * y; } int main() { int N; cin >> N; map mp; for (int i = 0; i < N; i++) { int No; cin >> No; int M, S; cin >> M >> S; for (int j = 0; j < M; j++) { string tag; cin >> tag; mp[tag] += S; } } vector> v; for (auto m : mp) { v.push_back(make_pair(-m.second, m.first)); } sort(v.begin(), v.end()); int size = min(10, (int)v.size()); for (int i = 0; i < size; i++) { cout << -v[i].first << ' ' << v[i].second << endl; } }