import ru.ifmo.testlib.*;
import ru.ifmo.testlib.Outcome.Type;

public class Check implements Checker {

    int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int m = inf.nextInt();
        int[][] a = new int[m][3];
        for (int i = 0; i < m; i++) {
            a[i][0] = inf.nextInt() - 1;
            a[i][1] = inf.nextInt() - 1;
        }
        String str1 = ouf.nextToken();
        String str2 = ans.nextToken();
        if (str1.equals("IMPOSSIBLE")) {
            if (str2.equals("IMPOSSIBLE")) {
                return new Outcome(Type.OK, "ok");
            } else {
                return new Outcome(Type.WA, "Solution exists");
            }
        }
        try {
            a[0][2] = Integer.parseInt(str1);
        } catch (NumberFormatException e) {
            return new Outcome(Type.WA, "Bad string");
        }       
        for (int i = 1; i < m; i++) {
            a[i][2] = ouf.nextInt();
        }
        int[] count = new int[m];
        int[] gcd = new int[n];
        for (int i = 0; i < m; i++) {
            if (a[i][2] < 1 || a[i][2] > m) {
                return new Outcome(Type.WA, "Incorrect edge number");
            }
            //	System.err.println(a[i][0]+" "+a[i][1]+" "+a[i][2]);
            count[a[i][2] - 1]++;
            gcd[a[i][0]] = gcd(gcd[a[i][0]], a[i][2]);
            gcd[a[i][1]] = gcd(gcd[a[i][1]], a[i][2]);
        }
        for (int i = 0; i < m; i++) {
            if (count[i] != 1) {
                return new Outcome(Type.WA, "Dont count of " + (i + 1)
                        + " number");
            }
        }
        for (int i = 0; i < n; i++) {
            if (gcd[i] != 1) {
                return new Outcome(Type.WA, "On vertex v = "+i+"GSD =" + gcd[i]);
            }
        }
        if (str1.equals("IMPOSSIBLE")) {
            return new Outcome(Type.FAIL, "AAAAAAAAAAA PANIC");
        } else {
            return new Outcome(Type.OK, "ok");
        }
    }
}
