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
import java.util.Scanner;

public class kar {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();
        String[] results = new String[t];
        for (int i = 0; i < t; i++) {
            results[i] = solve(scanner);
        }
        for (int i = 0; i < t; i++) {
            System.out.println(results[i]);
        }
    }

    private static String solve(Scanner scanner) {
        int sets = scanner.nextInt();
        int pairs = scanner.nextInt();

        int[] myWins = new int[sets];
        int[] hisWins = new int[sets];

        for (int i = 0; i < pairs; i++) {
            scanner.nextInt();
            boolean iWin = scanner.next().equals(">");
            int hisSetNr = scanner.nextInt();

            if (iWin) {
                myWins[hisSetNr - 1]++;
            } else {
                hisWins[hisSetNr - 1]++;
            }
        }

        for (int i = 0; i < sets; i++) {
            if (myWins[i] == sets) {
                return "WYGRANA";
            }
        }

        for (int i = 0; i < sets; i++) {
            if (hisWins[i] == 0) {
                return "REMIS";
            }
        }

        return "PRZEGRANA";
    }
}