n = int(input()) L = list(map(int, input().split())) t = int(input()) from collections import defaultdict D = defaultdict(lambda: [0]*(n+2)) C = [0]*n for i in range(t): s, p = map(str, input().split()) p = ord(p)-ord('A') C[p] += 1 D[s][p] += int(50*L[p]+50*L[p]/(0.8+0.2*C[p])) D[s][n] += int(50*L[p]+50*L[p]/(0.8+0.2*C[p])) D[s][n+1] = i D = list(D.items()) D.sort(key=lambda x: (-x[1][n], x[1][n+1])) for i, (s, l) in enumerate(D): print(i+1, s, *l[:-1])