#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 (auto v : V) cout << v.second << " " << 1e9 - v.first << "\n"; }