import collections N = int(input()) lsL = list(map(int,input().split())) alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' T = int(input()) score = collections.defaultdict(lambda:[0]*N) total = collections.defaultdict(lambda:(0,0)) rank = [1]*(N) for i in range(T): name,p = input().split() pn = alp.index(p) s = lsL[pn] score[name][pn] = 50*s + 500*s//(8+2*rank[pn]) a,b = total[name] total[name] = (a+score[name][pn],-i) rank[pn] += 1 aa = [] for key,val in total.items(): aa.append((val[0],val[1],key)) aa.sort(reverse=True) for i in range(len(aa)): print(i+1,aa[i][2],*score[aa[i][2]],aa[i][0])