#include using namespace std; int main() { map MA; int N; cin >> N; while (N--) { int no, M, S; cin >> no >> M >> S; while (M--) { string tag; cin >> tag; MA[tag] += S; } } vector> V; for (auto ma : MA) V.push_back({1e9 - ma.second, ma.first}); sort(V.begin(), V.end()); for (int i = 0; i < min(10, (int)V.size()); i++) cout << V.at(i).second << " " << 1e9 - V.at(i).first << "\n"; }