n = int(input()) L = list(map(int, input().split())) cnt = [0] * n score = {} time = {} T = int(input()) for i in range(T): name, p = input().split() p = ord(p) - 65 if name not in score: score[name] = [0] * n time[name] = i cnt[p] += 1 s = 50 * L[p] + int((50 * L[p]) / (0.8 + 0.2 * cnt[p]) + 0.00000001) score[name][p] += s lst = [] for name in score: tmp = [name] + score[name] + [sum(score[name])] + [time[name]] lst.append(tmp) lst.sort(key=lambda x:(-x[-2], x[-1])) for i, row in enumerate(lst, 1): print(i, *row[:-1])