#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; map mp; rep(_, n) { int no, m, s; cin >> no >> m >> s; rep(__, m) { string name; cin >> name; mp[name] += s; } } vector> ans; for (auto [name, score] : mp) { ans.push_back({ -score, name }); } sort(ans.begin(), ans.end()); rep(i, min(10, (int) ans.size())) { cout << ans[i].second << " " << -ans[i].first << endl; } return 0; }