#include #include #include #include #include #include using namespace std; int main(){ int N; cin >> N; map mp; for (int i = 0; i < N; i++){ int No; cin >> No; int M, S; cin >> M >> S; for (int j = 0; j < M; j++){ string Tag; cin >> Tag; mp[Tag] += S; } } vector> R; for (auto P : mp){ R.push_back(make_pair(- P.second, P.first)); } sort(R.begin(), R.end()); int cnt = min((int) R.size(), 10); for (int i = 0; i < cnt; i++){ cout << R[i].second << ' ' << - R[i].first << endl; } }