N = int(input()) from collections import defaultdict d = defaultdict(int) for _ in range(N): n = input() M,S = map(int,input().split()) for t in input().split(): d[t] += S l = [] for t in d: l.append((-d[t],t)) l.sort() for p,t in l[:10]: p = -p print(t,p)