#include using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) int main() { int n; cin >> n; map points; REP(i, n) { int no, m, s; cin >> no >> m >> s; REP(j, m) { string tag; cin >> tag; points[tag] += s; } } vector> v; for (auto au : points) { v.emplace_back(-au.second, au.first); } VSORT(v); n = min(10, int(v.size())); REP(i, n) { cout << v[i].second << " " << -v[i].first << endl; } return 0; }