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

public class kar {

    public static void main(String[] args) {
        //long start = Calendar.getInstance().getTimeInMillis();
        solution();
        //long stop = Calendar.getInstance().getTimeInMillis();
        //System.out.println("Time:" + (stop -start));
    }


    private static void solution() {

        Scanner sc = new Scanner(System.in);

        int numberOfTests = sc.nextInt();
        for (int i = 0; i < numberOfTests; i++)
            singleTestCaseSolution(sc);

    }

    private static void singleTestCaseSolution(Scanner sc) {

        int numberOfPackOfCards = sc.nextInt();
        int numberOfLines = sc.nextInt();

        boolean[] isHeWinning = new boolean[numberOfPackOfCards+1];
        int[] numberOfPackWinningWithHis = new int[numberOfPackOfCards+1];

        int mine, his;
        boolean mineBetter;

        for (int i = 0; i < numberOfLines; i++) {
            mine = sc.nextInt();
            mineBetter = sc.next().equals(">");
            his = sc.nextInt();
            if (!mineBetter)
                isHeWinning[his] = true;
            else
                numberOfPackWinningWithHis[his]++;
        }

        boolean iWon = false, iLost = true;
        for (int i = 1; i < numberOfPackOfCards+1; i++) {
            if (numberOfPackWinningWithHis[i] == numberOfPackOfCards)
                iWon = true;
            if (!isHeWinning[i])
                iLost = false;
        }

        if (iWon)
            System.out.println("WYGRANA");
        else if (iLost)
            System.out.println("PRZEGRANA");
        else
            System.out.println("REMIS");
    }
}