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
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)(v.size())
#define pb push_back
#define ft first
#define sd second
#define DBG(X) cerr << #X << " = " << X << endl
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
using namespace std;

/* #define LOCAL */
#ifndef LOCAL
#define cerr if(0)cout
#define endl "\n"
#endif

int main()
{
    #ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
    int T; cin >> T;
    rep(_, 0, T){
        int n, m; cin >> n >> m;
        vector<int>indeg(n, 0), outdeg(n, 0);
        rep(__, 0, m){
            int t1, t2; char dir;
            cin >> t1 >> dir >> t2;
            if(dir == '>'){
                indeg[t2 - 1]++;
            } else {
                outdeg[t2 - 1]++;
            }
        }
        if(any_of(all(indeg), [n](int i){return i == n; })){
            cout << "WYGRANA\n";
        } else if(all_of(all(outdeg), [](int o){return o >= 1; })){
            cout << "PRZEGRANA\n";
        } else {
            cout << "REMIS\n";
        }
    }
    return 0;
}