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
79
#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

/*************************************************************************/

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

    VI in(n,0), out(n,0);
    
    while (m--) {
        int a, b;
        char c;
        
        scanf("%d %c %d", &a, &c, &b);
        a--; b--;
        
        if (c == '>') {
            in[b]++;
        } else {
            out[b]++;
        }
    }
    
    if (*max_element(in.begin(), in.end()) == n) {
        printf("WYGRANA\n");
    } else if (*min_element(out.begin(), out.end()) == 0) {
        printf("REMIS\n");
    } else {
        printf("PRZEGRANA\n");
    }
}

/*************************************************************************/

int main() {
    int t;
    scanf("%d", &t);
    
    while (t--) {
        solve();        
    }

    return 0;
}

/*************************************************************************/