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

using namespace std;

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define FOR(i,n) REP(i,0,(int)n-1)
#define mp make_pair
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define VI vector<int>
#define fi first
#define se second

void solve(int test) {
	int n,m, MAXN;
	cin>>n>>m;

	MAXN = 2*n + 42;
	vector<VI> G;
	VI cnt;
	G.resize(MAXN), cnt.resize(MAXN);
	FOR(i,m) {
		int a,b;
		char c;
		cin>>a>>c>>b;
		//cout<<a<<" "<<c<<" "<<b<<"\n";
		a--; b--;
		if( c == '<' ) G[b + n].pb(a); 
		else G[a].pb(b + n);
	}
	int OutU = 0, OutV = 0;
	FOR(i, 2*n) {
		if(G[i].size() && i<n) OutU++;
		if(G[i].size() && i>=n) OutV++;
	}
	if(OutV == n) {
		cout<<"PRZEGRANA\n";
		return;
	}
	if(OutU < n && OutV < n) {
		cout<<"REMIS\n";
		return;
	}
	FOR(i,n)
		FOR(j, G[i].size())
			cnt[G[i][j]]++;
	REP(i,n,2*n-1) {
		if(cnt[i] == n) {
			cout<<"WYGRANA\n";
			return;
		} 
	}
	cout<<"REMIS\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	int t;
	cin>>t;
	FOR(i,t) solve(i);
	return 0;
}