/*--------------------------------------------------------------*/
/* ACM ICPC 2011-2012, NEERC                                    */
/* Northern Subregional Contest                                 */
/* St Petersburg, October 29, 2011                              */
/*--------------------------------------------------------------*/
/* Problem I. Immediate Delivery                                */
/*                                                              */
/* Original idea         Pavel Mavrin                           */
/* Problem statement     Pavel Mavrin                           */
/* Testset               Pavel Mavrin                           */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Pavel Mavrin                           */
/*--------------------------------------------------------------*/
 
import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;

/**
 * Checker for Northern QF'2011 Problem I: Immediate Delivery
 *
 * @author Pavel Mavrin
 */
public class Check implements Checker {
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int m = inf.nextInt();
        int[][] a = new int[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            int x = inf.nextInt();
            int y = inf.nextInt();
            int t = inf.nextInt();
            a[x][y] = t;
            a[y][x] = t;
        }
        int pa = ouf.nextInt();
        int ja = ans.nextInt();
        boolean[] z = new boolean[n + 1];
        int max = 0;
        for (int path = 1; path <= 2; path++) {
            int k = ouf.nextInt();
            int c = ouf.nextInt();
            if (c != 1) return new Outcome(Outcome.Type.WA, "Path " + path + " does not start with 1");
            if (k > 1000000) return new Outcome(Outcome.Type.WA, "Path " + path + " is longer then 1000000 roads, it can not be optimal.");
            int s = 0;
            for (int i = 0; i < k; i++) {
                int cc = ouf.nextInt();
                if (cc < 1 || cc > n) return new Outcome(Outcome.Type.WA, "Wrong junction number in path " + path + ": " + cc);
                if (a[c][cc] == 0) return new Outcome(Outcome.Type.WA, "No road from " + c + " to " + cc);
                s += a[c][cc];
                z[cc] = true;
                c = cc;
            }
            max = Math.max(max, s);
        }
        for (int i = 2; i <= n; i++) {
            if (!z[i]) {
                return new Outcome(Outcome.Type.WA, "Junction " + i + " was not visited");
            }
        }
        if (max != pa) return new Outcome(Outcome.Type.WA, "Time of last delivery calculated wrong " + pa + " instead of " + max);
        if (pa > ja) return new Outcome(Outcome.Type.WA, "Solution is not optimal: " + pa + " instead of " + ja);
        if (pa < ja) return new Outcome(Outcome.Type.FAIL, "Jury solution is not optimal: " + pa + " instead of " + ja);
        return new Outcome(Outcome.Type.OK, "");
    }
}
