1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class kar {

    public static final int SIZE = 100001;

    public void solve() throws IOException {
        InputReader reader = new InputReader(System.in);
        int t = reader.readInt();
        main: while (t-->0) {
            int n = reader.readInt(), m = reader.readInt();
            Set<Integer> lw = new HashSet<>(n);
            Set<Integer> rw = new HashSet<>(n);
            ArrayList<HashSet<Integer>> sets = new ArrayList<>(n);

            for (int i = 0; i <= n; i++)
                sets.add(new HashSet<>());

            for (int i = 0; i < m; i++) {
                int l = reader.readInt();
                char op = reader.nextString().charAt(0);
                int r = reader.readInt();
                if (op == '>') {
                    sets.get(l).add(r);
                    lw.add(l);
                }
                else {
                    rw.add(r);
                }
            }

            if (lw.size() == n) {
                boolean empty = sets.stream().skip(1).reduce((s1, s2) -> {
                    s1.retainAll(s2);
                    return s1;
                }).get().isEmpty();

                if (!empty) {
                    System.out.println("WYGRANA");
                    continue;
                }
            }

            if (rw.size() == n)
                System.out.println("PRZEGRANA");
            else
                System.out.println("REMIS");
        }
    }

    public static void main(String[] args) throws IOException {
        new kar().solve();
    }

    private class InputReader {
        private final BufferedReader reader;

        private StringTokenizer tokenizer = new StringTokenizer("", " ");

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 100 * 1000);
        }

        String nextString() throws IOException {
            if (!tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(reader.readLine(), " ");
            return tokenizer.nextToken();
        }

        int readInt() throws IOException {
            return Integer.parseInt(nextString());
        }
    }
}