#include using namespace std; map cnt; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, no, m, s; string S; cin >> n; for (int i = 0; i < n; i++) { cin >> no; cin >> m >> s; for (int j = 0; j < m; j++) { cin >> S; cnt[S] += s; } } vector > v; for (auto it : cnt) { v.push_back(make_pair(-it.second, it.first)); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { if (i == 10) break; cout << v[i].second << ' ' << -v[i].first << '\n'; } return 0; }