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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class kar {

    public static void main(String[] args) {
        try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int t = Integer.parseInt(reader.readLine());
            StringBuilder output = new StringBuilder();

            for (int i = 0; i < t; i++) {
                resolveTestCase(reader, output);
            }

            System.out.print(output);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void resolveTestCase(BufferedReader reader, StringBuilder builder) throws IOException {
        String testCaseHeader = reader.readLine();

        int n = Integer.parseInt(testCaseHeader.split(" ")[0]);
        int m = Integer.parseInt(testCaseHeader.split(" ")[1]);

        int[] playerAWinningDecks = new int[n];
        int[] playerBWinningDecks = new int[n];

        int[] playerALoosingDecks = new int[n];
        int[] playerBLoosingDecks = new int[n];


        for (int i = 0; i < m; i++) {
            String[] parts = reader.readLine().split(" ");
            int a = Integer.parseInt(parts[0]) - 1;
            int b = Integer.parseInt(parts[2]) - 1;

            if (parts[1].equals(">")) {
                playerAWinningDecks[a]++;
                playerBLoosingDecks[b]++;
            } else {
                playerALoosingDecks[a]++;
                playerBWinningDecks[b]++;
            }
        }

        long playerAWinningCardsCounter = 0;
        long playerBWinningCardsCounter = 0;

        for (int i = 0; i < n; i++) {
            if (playerAWinningDecks[i] > 0) {
                playerAWinningCardsCounter++;
            }

            if (playerBWinningDecks[i] > 0) {
                playerBWinningCardsCounter++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (playerBWinningCardsCounter >= n) {
                builder.append("PRZEGRANA\n");
                return;
            } else if (playerBLoosingDecks[i] >= n && playerAWinningCardsCounter >= n) {
                builder.append("WYGRANA\n");
                return;
            }
        }

        builder.append("REMIS\n");
    }

}