
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;

public class arbitrage {

    private static class Path {

        final private Set<String> in;
        final private String first;
        final private String last;
        final private int scoreup;
        final private int scoredown;
        final private boolean fin;

        public Path(String f, String l, int u, int d) {
            in = new HashSet<String>();
            first = f;
            last = l;
            scoreup = u;
            scoredown = d;
            fin = false;
        }

        public Path(Path p, String last, int scoreup, int scoredown) {
            in = new HashSet<String>(p.in);
            in.add(last);
            this.first = p.first;
            this.last = last;
            this.scoreup = p.scoreup * scoreup;
            this.scoredown = p.scoredown * scoredown;

            if (this.first.equals(this.last)) {
                fin = true;
            } else {
                this.fin = false;
            }
        }

        public boolean canextend(String key) {
            return !in.contains(key);
        }

        public boolean isarbit() {
            return scoreup > scoredown;
        }

        @Override
        public String toString() {
            return String.format("%s - %s (%d:%d): %s", first, last, scoreup, scoredown, fin);
        }
    }
    private static Map<String, Map<String, Path>> exrate = new HashMap<String, Map<String, Path>>();

    private static void setRatio(String from, String to, int u, int d) {
        if (!exrate.containsKey(from)) {
            exrate.put(from, new HashMap<String, Path>());
        }

        exrate.get(from).put(to, new Path(from, to, u, d));
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));

        while (true) {
            int curs = s.nextInt();

            if (curs == 0) {
                break;
            }

            for (int i = 0; i < curs; i++) {
                s.next();
            }

            int rates = s.nextInt();

            for (int i = 0; i < rates; i++) {
                String from = s.next();
                String to = s.next();
                String r[] = s.next().split(":");
                int ru = Integer.valueOf(r[1]);
                int rd = Integer.valueOf(r[0]);

                setRatio(from, to, ru, rd);
            }

            for (String c : exrate.keySet()) {
              //  System.out.println("rates: " + exrate.get(c));
            }

            boolean arb = false;

            Stack<Path> stack = new Stack<Path>();

            for (String cur : exrate.keySet()) {
               // System.out.println("eval: " + cur);

                stack.clear();

                stack.push(new Path(cur, cur, 1, 1));

                while (!stack.empty()) {
                    Path p = stack.pop();
                    //System.out.println("pop: " + p);

                    if (p.fin) {
                        if (p.isarbit()) {
                            arb = true;
                            break;
                        }
                    } else {
                        if (exrate.containsKey(p.last)) {
                            Map<String, Path> xrate = exrate.get(p.last);

                            for (String nc : xrate.keySet()) {
                                if (p.canextend(nc))
                                {
                                String last = nc;
                                int sp = xrate.get(nc).scoreup;
                                int sd = xrate.get(nc).scoredown;
                                Path n = new Path(p, last, sp, sd);
                                stack.push(n);
                                //System.out.println("push: " + n);
                                }
                            }
                        }
                    }
                }
            }


            printOutput(arb);
        }
    }

    private static void printOutput(boolean arb) {
        if (arb) {
            System.out.println("Arbitrage");
        } else {
            System.out.println("Ok");
        }
    }
}
