#include #include #include #include #include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; using tag = array; map mp; for (int i = 0; i < n; i++) { int j; cin >> j; int m, s; cin >> m >> s; for (int k = 0; k < m; k++) { tag t = {}; cin >> &t[0]; mp[t] += s; } } vector> a; a.reserve(n); for (const auto& p : mp) { a.push_back(p); } stable_sort(a.begin(), a.end(), [](const pair& p0, const pair& p1) { return p0.second > p1.second; }); for (int i = 0; i < min(10, (int)a.size()); i++) { cout << &a[i].first[0] << ' ' << a[i].second << '\n'; } return 0; }