from math import floor N = int(input()) L = list(map(int, input().split())) rank = [1] * N alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' trans = {alpha[i]: i for i in range(26)} T = int(input()) point = {} last = {} for i in range(T): name_i, pi = input().split() n = trans[pi] if name_i not in point: point[name_i] = [0] * N point[name_i][n] = floor(50 * L[n] + 50 * L[n] / (0.8 + 0.2 * rank[n])) rank[n] += 1 last[name_i] = i names = list(point.keys()) names.sort(key=lambda k: (-sum(point[k]), last[k])) for i in range(len(names)): name_i = names[i] print(i+1, name_i, *point[name_i], sum(point[name_i]))