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
#include <cstdio>
#include <algorithm>

static const int MAX_N = 100 * 1000;
int indeg[MAX_N];  // (>) How many of my stacks beat this stack
int outdeg[MAX_N]; // (<) How many of my stacks are beaten by this stack

void testCase()
{
    int n, m;
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++)
        indeg[i] = 0;
    for (int i = 0; i < n; i++)
        outdeg[i] = 0;

    for (int i = 0; i < m; i++) {
        int b;
        char sign;
        scanf("%*d %c %d", &sign, &b);

        if (sign == '>')
            indeg[b - 1]++;
        else
            outdeg[b - 1]++;
    }

    // Check the criterion for a winning strategy
    for (int i = 0; i < n; i++) {
        // If the opponent has a stack that loses
        // with all of my stacks, I can always win
        if (indeg[i] == n) {
            puts("WYGRANA");
            return;
        }
        // printf("I %d\n", indeg[i]);
    }

    // Can't win, but maybe I can draw?

    // Check the criterion for an at-least-draw-strategy
    for (int i = 0; i < n; i++) {
        // If the opponent has at least one stack
        // that doesn't beat any of my stacks,
        // I can always draw or win (in this case
        // only draw because we checked we can't win)
        if (outdeg[i] == 0) {
            puts("REMIS");
            return;
        }
        // printf("O %d\n", outdeg[i]);
    }

    // Unfortunately, the opponent has the winning strategy...
    // I can't win :(
    puts("PRZEGRANA");
}

int main()
{
    int t;
    scanf("%d", &t);

    while (t --> 0) {
        testCase();
    }

    return 0;
}