#!coding:utf-8 ref=[chr(i) for i in range(65,65+26)] N=int(raw_input()) L=map(int,raw_input().split()) T=int(raw_input()) Timing=[1]*N kekka={} for i in range(T): NP=raw_input().split() Name=NP[0] Prob_No=ref.index(NP[1]) Point=50*L[Prob_No]+50*L[Prob_No]/(0.8+0.2*Timing[Prob_No]) if Name in kekka: kekka[Name][0]=kekka[Name][0]+Point kekka[Name][1][Prob_No]=Point kekka[Name][2]=N-i else: kekka[Name]=[0,[0]*N,0] kekka[Name][0]=kekka[Name][0]+Point kekka[Name][1][Prob_No]=Point kekka[Name][2]=N-i l_kekka=[] for k in kekka.keys(): l_kekka.append([k,kekka[k]]) l_kekka=sorted(l_kekka, key=lambda x:(x[1][0],x[1][2]), reverse=True) #print l_kekka #[['ame', [400.0, [200.0, 200.0, 0], 0]], ['yuki', [400.0, [200.0, 200.0, 0], 1]]] for i in l_kekka: i[1][1]=map(str,map(int,i[1][1])) st=i[0]+" "+str(" ".join(i[1][1]))+ " "+str(int(i[1][0])) print st