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<String, Integer> names = new HashMap<String, Integer>();
			
			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(":");
				
				rates[a][b][0] = Integer.parseInt(toks[0]);
				rates[a][b][1] = Integer.parseInt(toks[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;
	}
}