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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define sz(x) int((x).size())
#define dbg(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (__typeof(t.begin()) i = t.begin(); i != t.end(); ++i)
#define fi first
#define se second
#define pii pair<int,int>
const int INF = 2000000000;
const int MAXN = 200010;
int deg1[MAXN], deg2[MAXN];

int main() {
    int t;
    scanf("%d", &t);
    FOR(iii,t) {
        int n,m;
        scanf("%d %d", &n, &m);
        FOR(i,n) {
            deg1[i] = 0;
            deg2[i] = 0;
        }
        FOR(i,m) {
            int a,b;
            char w;
            scanf("%d %c %d",&a, &w, &b);
            a--;
            b--;
            if (w=='>') {
                deg1[b]++;
            } else {
                deg2[b]++;
            }
        }
        int result = -1;
        FOR (i,n) {
            if (deg1[i] == n) {
                result = 1;
                break;
            }
        }

        if (result == -1) {
            FOR (i,n) {
                if (deg2[i] == 0) {
                    result = 0;
                    break;
                }
            }
        }
        if (result == 1)
            printf("WYGRANA\n");
        if (result == 0)
            printf("REMIS\n");
        if (result == -1)
            printf("PRZEGRANA\n");
    }
    return 0;
}