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
// Karol Kosinski
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;

const int MX = 100005;
int A[MX], B[MX];

bool A_wins(int n)
{
        FOR(i,1,n)
                if (A[i] == n)
                        return true;
        return false;
}

bool B_wins(int n)
{
        FOR(i,1,n)
                if (B[i] == 0)
                        return false;
        return true;
}

int main()
{
        int z; scanf("%d", &z);
        while (z--)
        {
                int n, m;
                scanf("%d%d", &n, &m);
                FOR(i,1,n)
                        A[i] = B[i] = 0;
                FOR(i,1,m)
                {
                        int b; char w[2];
                        scanf("%*d%s%d", w, &b);
                        if (w[0] == '>')
                                ++A[b];
                        else
                                B[b] = 1;
                }
                if (A_wins(n))
                        printf("WYGRANA\n");
                else if (B_wins(n))
                        printf("PRZEGRANA\n");
                else
                        printf("REMIS\n");
        }
        return 0;
}