import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] levels = new int[n]; for (int i = 0; i < n; i++) { levels[i] = sc.nextInt(); } int[] ranks = new int[n]; int t = sc.nextInt(); HashMap players = new HashMap<>(); Player.size = n; for (int i = 0; i < t; i++) { String name = sc.next(); int idx = sc.next().charAt(0) - 'A'; ranks[idx]++; if (!players.containsKey(name)) { players.put(name, new Player(name)); } players.get(name).addScore(idx, 50 * levels[idx] + 500 * levels[idx] / (8 + 2 * ranks[idx]), i); } ArrayList ans = new ArrayList<>(); ans.addAll(players.values()); Collections.sort(ans); StringBuilder sb = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { sb.append(i + 1).append(" ").append(ans.get(i)).append("\n"); } System.out.print(sb); } static class Player implements Comparable { static int size; String name; int[] scores; int sum; int last; public Player(String name) { this.name = name; scores = new int[size]; } public void addScore(int idx, int value, int time) { scores[idx] = value; sum += value; last = time; } public int compareTo(Player another) { if (sum == another.sum) { return last - another.last; } else { return another.sum - sum; } } public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name).append(" "); for (int x : scores) { sb.append(x).append(" "); } sb.append(sum); return sb.toString(); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }