import java.util.*; import java.io.*; public class arbitrage { public static class Solution { public double MAX = 999999999999.0; public class Exchange { public Currency i; public double r; public Exchange(Currency id, double ra) { i=id;r=ra; } } public class Currency { public double d=MAX; public boolean b=true; public LinkedList e=new LinkedList(); } public void run() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String line; int N, M ; double r; while ((N=Integer.parseInt((line = reader.readLine())))!=0) { HashMap table=new HashMap(2*N); line = reader.readLine(); String[] cs = line.split(" "); for (int i = 0; i < cs.length; i++) { table.put(cs[i],new Currency()); } M=Integer.parseInt(line = reader.readLine()); while (M-- > 0) { StringTokenizer t = new StringTokenizer(reader.readLine(), " :"); Currency A1 = table.get(t.nextToken()); Currency A2 = table.get(t.nextToken()); r=Integer.parseInt(t.nextToken()); r=Integer.parseInt(t.nextToken())/(double)r; A1.e.add(new Exchange(A2,-java.lang.Math.log10(r))); } boolean OK = true; Collection cur = table.values(); for (int i = 0 ; i < N ; i++) { for (Currency c : cur) { for (Exchange e : c.e) { if (c.d + e.r < e.i.d) { e.i.d = c.d + e.r; } } } } for (Currency c : cur) { for (Exchange e : c.e) { if (c.d + e.r < e.i.d) { OK = false ; } } } System.out.println((OK ? "Ok": "Arbitrage")); } } } public static void main(String[] arg) throws IOException { (new Solution()).run(); } }