import sys from itertools import islice from collections import defaultdict from dataclasses import dataclass def _score(star, rank): return 50 * star + int((500 * star) // (8 + 2 * rank)) def _solve(N, L, T, queries): key = lambda a: (a[-2], -a[-1]) scores = defaultdict(lambda: [''] + [0] * (N + 2)) rank = [0] * N c_a = ord('A') for i, (name, q) in enumerate(queries): index = ord(q) - c_a rank[index] += 1 score = _score(L[index], rank[index]) scores[name][0] = name scores[name][index + 1] = score scores[name][-2] += score scores[name][-1] = i return enumerate(sorted(scores.values(), key=key, reverse=True), 1) def solve(in_): N = int(next(in_)) L = tuple(map(int, next(in_).split())) T = int(next(in_)) queries = (line.split() for line in islice(in_, T)) return _solve(N, L, T, queries) def main(): answer = solve(sys.stdin) for i, v in answer: print(i, ' '.join(map(str, v[:-1]))) if __name__ == '__main__': main()