def f(x, n): return 50 * x + (500 * x)//(8 + 2 * n) N = int(input()) L = list(map(int, input().split())) T = int(input()) DS, D = dict(), dict() cnt = [1] * N ans = [] for i in range(T): name, P = input().split() n = ord(P) - ord("A") if name in D: D[name].append([f(L[n], cnt[n]), n]) else: D[name] = [[f(L[n], cnt[n]), n]] cnt[n] += 1 if name in DS: DS[name] = [DS[name][0] + D[name][-1][0], i] else: DS[name] = [D[name][-1][0], i] lst = [] for k, v in DS.items(): lst.append([-v[0], v[1], k]) lst.sort() idx = 1 for v0, v1, k in lst: # print("test", v0, v1, k) temp = [idx, k] temp2 = [0] * N for d0, d1 in D[k]: temp2[d1] = d0 temp.extend(temp2) temp.append(-v0) print(*temp) idx += 1