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>
#define loop(i,j,s) for(int i=j;i<s;i++)
#define loopback(i,j,s) for(int i=j;i>=s;i--)
#define pln( x ) cout << x << "\n"
#define ps( x ) cout << x << " "
#define entr cout << "\n" 
#define pcnt(i) __builtin_popcount(i)
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
const int INFTY=20000000;
const int MAX=500100;
const int MOD=10000000;

void coutTab(int* tab,int n){
	loop(i,0,n){
		cout<<tab[i]<<" ";
	}
	cout<<"\n";
}
//------------------------------------------
bool was1[MAX],was2[MAX];
int main(){
	ios_base::sync_with_stdio(0);
	int T,n,m;
	int a,b;
	char w;
	int winning1,winning2;
	cin>>T;
	while(T--){
		loop(i,0,n){
			was1[i]=0;
			was2[i]=0;
		}
		winning1=0;
		winning2=0;
		cin>>n>>m;
		loop(i,0,m){
			cin>>a>>w>>b;
			if(w=='>'){
				if(!was1[a]){ 
					winning1++;
					was1[a]=1;
				}	
			}else{
				if(!was2[b]){ 
					winning2++;
					was2[b]=1;
				}
			}
		}
		if(winning1<n&&winning2<n){
			pln("REMIS");
		}else if(winning1==n&&winning2<n){
			pln("WYGRANA");
		}else if(winning1<n&&winning2==n){
			pln("PRZEGRANA");
		}else{
			pln("PRZEGRANA");
		}
	}
}