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

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

    int *bit_dst    = new int[n];
    int *bit_source = new int[n];

    bzero(bit_dst, sizeof(int) * n);
    bzero(bit_source, sizeof(int) * n);

    while (m--) {
        int a, b;
        char w;
        scanf("%d %c %d", &a, &w, &b);
        if (w == '>') {
            bit_dst[b - 1] += 1;
        } else {
            bit_source[b - 1] += 1;
        }
    }
    
    bool win = false;
    int bit_winning = 0;

    for (int i = 0; i < n; i++) {
        if (bit_dst[i] == n) {
            win = true;
            break;
        }
        if (bit_source[i] > 0)
            bit_winning++;
    }   

    if (win)
        printf("WYGRANA\n");
    else if (bit_winning == n)
        printf("PRZEGRANA\n");
    else
        printf("REMIS\n");

    delete(bit_dst);
    delete(bit_source);
}

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

    while (t--)
        task(); 

    return 0;
}