import java.util.*; import java.util.*; public class arbitrage { static int[][][] rates; static boolean[][] was; static int c; static int start; public static void main(String[] args) { Scanner sc = new Scanner(System.in); c = -1; while (c != 0) { c = sc.nextInt(); if (c == 0) { break; } HashMap names = new HashMap(); sc.nextLine(); String[] toks = sc.nextLine().split(" "); for (int i = 0; i < c; i++) { names.put(toks[i], i); } int r = sc.nextInt();sc.nextLine(); rates = new int[c][c][2]; for (int i = 0; i < r; i++) { String line = sc.nextLine(); toks = line.split(" "); int a = names.get(toks[0]); int b = names.get(toks[1]); toks = toks[2].split(":"); int[] newr = new int[2]; newr[0] = Integer.parseInt(toks[0]); newr[1] = Integer.parseInt(toks[1]); double oldrat = -1; if (rates[a][b][1] != 0) { oldrat = rates[a][b][0] / (double)rates[a][b][1]; } double newrat = newr[0] / (double)newr[1]; if (newrat < oldrat || oldrat == -1) { rates[a][b][0] = newr[0]; rates[a][b][1] = newr[1]; } } // dfs boolean arb = false; for (int i = 0; i < c; i++) { was = new boolean[c][c]; //was[i] = true; start = i; int[] res = dfs(i, new int[] {1, 1}); if (res[0] < res[1]) { System.out.println("Arbitrage"); arb = true; break; } } if (!arb) { System.out.println("Ok"); } } } public static int[] dfs(int from, int[] diff) { for (int i = 0; i < c; i++) { if (was[from][i]) { continue; } if (rates[from][i][0] == 0) { continue; } //System.out.println(from + " " + c); was[from][i] = true; int[] newDiff = new int[2]; newDiff[0] = diff[0] * rates[from][i][0]; newDiff[1] = diff[1] * rates[from][i][1]; //System.out.println(from + " > " + i + " = " + Arrays.toString(newDiff)); if (i == start) { return newDiff; } int[] res = dfs(i, newDiff); was[from][i] = false; if (res[0] < res[1]) { return res; } } //if (from != start) { return new int[] {1, 1}; //} //return diff; } }