import java.io.*; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.*; /** * * @author cteam01 */ public class arbitrage { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; int u, h; while ((line = br.readLine()) != null) { u = Integer.parseInt(line); if (u == 0) { System.exit(0); } double d[] = new double[u]; Map uzly = new HashMap(); d[0] = 0; Arrays.fill(d, 1, u, 1e9); line = br.readLine(); String[] tokens = line.split(" "); for (int i = 0; i < u; i++) { uzly.put(tokens[i], i); } line = br.readLine(); h = Integer.parseInt(line); Hrana[] hrany = new Hrana[h]; for (int i = 0; i < h; i++) { line = br.readLine(); tokens = line.split(" "); int u1 = uzly.get(tokens[0]); int u2 = uzly.get(tokens[1]); tokens = tokens[2].split(":"); double w = Double.parseDouble(tokens[0])/Double.parseDouble(tokens[1]); w = Math.log(w); hrany[i] = new Hrana(u1,u2,w); } for (int i = 0; i < u-1; i++) { for (Hrana hr : hrany) { if(d[hr.v] > d[hr.u] + hr.w){ d[hr.v] = d[hr.u] + hr.w; } } } boolean ok = true; for (Hrana hr : hrany) { if(d[hr.v] > d[hr.u] + hr.w){ ok = false; } } if(ok){ System.out.println("Ok"); } else { System.out.println("Arbitrage"); } } } private static class Hrana { int u, v; double w; public Hrana(int u, int v, double w) { this.u = u; this.v = v; this.w = w; } } }