#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; map mp; while(n--) { int no, m, s; cin >> no >> m >> s; string tag; while(m--) { cin >> tag; mp[tag] += s; } } vector> ans; for(auto i : mp) { ans.emplace_back(i.first, i.second); } sort(ans.begin(), ans.end(), [](pair x, pair y) -> bool {if(x.second != y.second) return x.second > y.second; else return x.first < y.first;}); for(int i = 0; i < ans.size(); i++) { if(i == 10) break; cout << ans[i].first << " " << ans[i].second << '\n'; } return 0; }