#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; unordered_map d; for (int i = 0; i < N; ++i) { int No; int M, S; cin >> No; cin >> M >> S; for (int j = 0; j < M; ++j) { string tag; cin >> tag; if (d.find(tag) != d.end()) { d[tag] += S; } else { d[tag] = S; } } } vector< pair > vp; for (auto &i : d) { vp.emplace_back(i.first, i.second); } sort(vp.begin(), vp.end(), [](const auto& x, const auto& y) { return (x.second != y.second ? x.second > y.second : x.first < y.first); }); for (int i = 0; i < vp.size() && i < 10; ++i) { cout << vp[i].first << " "<< vp[i].second << endl; } return 0; }