#include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template using GPQ = priority_queue, greater>; int main() { int n; cin >> n; map m; for (int i = 0; i < n; ++i) { int xxxxx; cin >> xxxxx; int a, b; cin >> a >> b; for (int j = 0; j < a; ++j) { string s; cin >> s; m[s] += b; } } GPQ> Q; for (auto &&k : m) { if(k.second){ Q.emplace(-k.second, k.first); } } for (int i = 0; i < 10 && !Q.empty(); ++i) { auto p = Q.top(); Q.pop(); cout << p.second << " " << -p.first << "\n"; } return 0; }