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
#include<bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define FOREACH(i,c) for( __typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define ALL(k) (k).begin(),(k).end()
#define e1 first 
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back 
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
const bool print=false;
const int MAXN=100111;
int t1[MAXN],t2[MAXN];
int tw[MAXN];
int readint(){
	char a=getchar_unlocked();
	while(a<'0'||a>'9') a=getchar_unlocked();
	int wyn=0;
	while('0'<=a&&a<='9') wyn=10*wyn+a-'0',a=getchar_unlocked();
	return wyn;
}
char readsgn(){
	char a=getchar_unlocked();
	while(a!='<'&&a!='>') a=getchar_unlocked();
	return a;
}
	

main(){
	int t;scanf("%d",&t);
	while(t--){
		//printf("%d\n",t);
		int n=readint(),m=readint();
		FOR(i,1,m){
			int a=readint();char w=readsgn();int b=readint();
			if(w=='<') t2[b]++;
			else t1[a]++,tw[b]++;
		}
		int all1=1,all2=1;
		int degn=0;
		FOR(i,1,n){
			if(tw[i]==n) degn=1;
			if(t1[i]==0) all1=0;
			if(t2[i]==0) all2=0;
			t1[i]=t2[i]=tw[i]=0;
		}
		puts(all2?"PRZEGRANA":((all1&&degn>0)?"WYGRANA":"REMIS"));
	}
}