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
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int testcase() {
        int n,m,i,*a,*b,x,y,ma,mb;
        char c;

        scanf("%d %d\n", &n,&m);
        a = malloc(n*sizeof(*a));
        b = malloc(n*sizeof(*b));
        bzero(a, n*sizeof(*a));
        bzero(b, n*sizeof(*b));
        for (i=0; i<m; ++i) {
                scanf("%d %c %d\n", &x, &c, &y);
                if (c == '>') {
                        a[x-1]++;
                } else {
                        b[y-1]++;
                }
        }
        ma = 0;
        mb = 0;
        for (i=0; i<n; ++i) {
                if (a[i]) ma++;
                if (b[i]) mb++;
        }
        free(a); free(b);
        if (ma > (n-1))
                return 1;
        if (mb > (n-1))
                return -1;

        return 0;
}



int main() {
        int t,r;
        scanf("%d\n", &t);
        while (t--) {
                r = testcase();
                if (r > 0) printf("WYGRANA\n");
                if (r < 0) printf("PRZEGRANA\n");
                if (r == 0) printf("REMIS\n");
        }
        return 0;
}