#!/usr/bin/env pypy3 import collections import heapq def sub_score(level, ac_pos): return 50 * level + 500 * level // (8 + 2 * ac_pos) def alpha2int(c): return ord(c) - ord("A") def main(): n = int(input()) ls = [int(l) for l in input().split()] t = int(input()) pq = [] ac_pos = [1 for _ in range(n)] total_score = collections.defaultdict(int) each_score = collections.defaultdict(lambda: [0 for _ in range(n)]) for i in range(t): name, p = input().split() p_id = alpha2int(p) s = sub_score(ls[p_id], ac_pos[p_id]) ac_pos[p_id] += 1 each_score[name][p_id] += s total_score[name] += s heapq.heappush(pq, (-total_score[name], i, name)) processed_names = set() j = 0 while pq: total, _, name = heapq.heappop(pq) if name not in processed_names: processed_names.add(name) j += 1 mes = " ".join(str(x) for x in each_score[name]) print(j, name, mes, -total) if __name__ == '__main__': main()