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

#define FOR(i,n) for(int i=0; i < int(n); ++i)
#define FO(i,a,b) for(int i=int(a); i<int(b); ++i)

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

typedef vector<int> vi;
typedef vector<vi> vvi;

#define siz size()*1LL

#define fi first
#define se second

#define ASS assert

#define remin(a,b) a=min(a,b)
#define remax(a,b) a=max(a,b)

#define ALL(c) (c).begin(), (c).end()

#define NL '\n'


int tc(){
	int n,m;
	scanf("%d%d", &n, &m);
	
	vi indeg(n), outdeg(n);
	
	FOR(i,m){
		int a,b;
		char z;
		scanf("%d %c%d", &a, &z, &b);
		--a; --b;
		
		if(z=='>') indeg[b]++;
		else outdeg[b]++;
	}
	
	FOR(i,n) if(indeg[i] == n) return 1;
	FOR(i,n) if(outdeg[i] == 0) return 0;
	return -1;
}

int main(){
	ios_base::sync_with_stdio(0);
	
	int t;
	scanf("%d", &t);
	FOR(i,t){
		int r = tc();
		if(r == 1) puts("WYGRANA");
		else if(r == -1) puts("PRZEGRANA");
		else puts("REMIS");
	}
	
	return 0;
}