import math N = int(input()) L = list(map(int, input().split())) T = int(input()) submissions = [input().split() for _ in range(T)] problem_counts = [0] * N users = {} for timestamp, (name, p_char) in enumerate(submissions, 1): p_idx = ord(p_char) - ord('A') problem_counts[p_idx] += 1 ac_rank = problem_counts[p_idx] if name not in users: users[name] = { 'name': name, 'problems': {}, 'last_submission_time': 0, 'scores': None, 'sum_cached': 0, } user = users[name] user['problems'][p_idx] = ac_rank user['last_submission_time'] = timestamp for user in users.values(): scores = [0] * N sum_score = 0 for p_idx in range(N): if p_idx in user['problems']: ac_rank = user['problems'][p_idx] li = L[p_idx] d = 0.8 + 0.2 * ac_rank score_part1 = 50 * li score_part2 = (50 * li) / d total = score_part1 + score_part2 score = math.floor(total) scores[p_idx] = score sum_score += score user['scores'] = scores user['sum_cached'] = sum_score sorted_users = sorted(users.values(), key=lambda u: (-u['sum_cached'], u['last_submission_time'])) for rank, user in enumerate(sorted_users, 1): output_parts = [str(rank), user['name']] + list(map(str, user['scores'])) + [str(user['sum_cached'])] print(' '.join(output_parts))