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
71
72
73
74
75
76
77
78
// Gra w karty [A], Jakub Szczugiel (bledna odpowiedz)
#include <bits/stdc++.h>

using namespace std;

struct karta{ int rate, id; };

karta tab[400000];
vector<int> g[400000];

bool comp(karta a, karta b)
{
    return a.rate < b.rate;
}


short check(int a, int b)
{
    a--; b--;
    for(int i = 0; i < g[a].size(); i++) if(g[a][i] == b) return 1;
    for(int i = 0; i < g[b].size(); i++) if(g[b][i] == a) return -1;
    return 0;
}


int main()
{
    ios_base::sync_with_stdio(0);

    int t, n, m;
    cin >> t;


    int a, b;
    char x;

    while(t--)
    {



        cin >> n >> m;
        for(int i = 0; i < n; i++){
            tab[i].rate = tab[n+i].rate = 0;
            tab[i].id =  tab[n+i].id = i+1;
            g[i].clear();
            g[n+i].clear();
        }



        for(int i = 0; i < m; i++)
        {
            cin >> a >> x >> b;
            a--;
            b--;
            if(x == '>'){
                tab[a].rate++;
                tab[n+b].rate--;
                g[a].push_back(n+b);
            }
            else{
                tab[n+b].rate++;
                tab[a].rate--;
                g[n+b].push_back(a);
            }
        }

        sort(tab, tab+n, comp);
        sort(tab+n, tab+2*n, comp);

        int odp = check(tab[0].id, n+tab[n].id);

        if(odp == 1) cout << "WYGRANA\n";
        else if(odp == -1) cout << "PRZEGRANA\n";
        else cout << "REMIS\n";
    }
}