N = int(input()) from collections import defaultdict d = defaultdict(int) for i in range(N): _ = input() _, S = map(int, input().split()) for t in input().split(): d[t] += S X = [[-v, k] for k, v in d.items()] X.sort() for i in range(min(10, len(X))): print(X[i][1], -X[i][0])