#include #include #include #include #include #include #include #include #include #include #include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() using namespace std; int main() { int N; cin >> N; map tb; int no = 0; int m = -1; int s = 0; for (int i = 0; i < N; i++) { cin >>no>> m >> s; for (int j = 0; j < m; j++) { string tag; cin >> tag; tb[tag] += s; } } vector> v; fore(p, tb)v.push_back({-p.second,p.first}); sort(v.begin(), v.end()); int n = min(10, (int)v.size()); rep(i, 0, n)cout << v[i].second << " " << -v[i].first << endl; }