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
#include <cstdio>
#include <set>
#include <map>

typedef std::set<int> SET;
typedef std::map<int, SET> MAP;

void test(void)
{
    int n, m, i, a, b;
    char w[16];
    MAP Aw, Bw, Bl;

    scanf("%d%d", &n, &m);

    for (i = 0; i < m; i++) {
        scanf("%d%s%d", &a, w, &b);

        if (*w == '>') {
            Aw[a].insert(b);
            Bl[b].insert(a);
        }

        else if (*w == '<') {
            Bw[b].insert(a);
        }
    }

    if (Bw.size() == n)
        printf("PRZEGRANA\n");

    else if (Aw.size() < n)
        printf("REMIS\n");

    else {
        for (MAP::iterator i1 = Bl.begin(); i1 != Bl.end(); ++i1)
            if (i1->second.size() < n) {
                for (SET::iterator i2 = i1->second.begin(); i2 != i1->second.end(); ++i2) {
                    Aw[*i2].erase(i1->first);

                    if (!Aw[*i2].size())
                        Aw.erase(*i2);
                }
            }

        if (Aw.size())
            printf("WYGRANA\n");

        else
            printf("REMIS\n");
    }
}

int main(void)
{
    int t;

    scanf("%d", &t);

    while(t-- > 0)
        test();

    return 0;
}