#include using namespace std; void tag_628(void) { int n; cin >> n; map tag; int no, m, s; string tags; for (int i = 0; i < n; i++) { cin >> no; cin >> m >> s; for (int j = 0; j < m; j++) { cin >> tags; tag[tags] += s; } } map::iterator tag_ptr; map> ans; for (tag_ptr = tag.begin(); tag_ptr != tag.end(); tag_ptr++) { ans[(-1) * tag_ptr->second].push_back(tag_ptr->first); } map>::iterator ansptr; int cnt = 0; for (ansptr = ans.begin(); ansptr != ans.end(); ansptr++) { if ((int)ansptr->second.size() > 1) sort(ansptr->second.begin(), ansptr->second.end()); for (int j = 0; j < (int)ansptr->second.size(); j++) { cout << ansptr->second[j] << " " << ansptr->first * (-1) << endl; cnt++; if (cnt == 10) break; } if (cnt == 10) break; } } int main(void) { tag_628(); return 0; }