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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 100100;

int n,m;
vector<int> win[N], lose[N];

bool canwin() {
	FOR(i,n) if (win[i].size()==n) return true;
	return false;
}

bool candraw() {
	FOR(i,n) if (lose[i].size()==0) return true;
	return false;
}

void test() {
	scanf("%d%d", &n, &m);
	FOR(i,n) {
		win[i].clear();
		lose[i].clear();
	}
	FOR(i,m) {
		int a,b;
		char ss[5];
		scanf("%d%s%d", &a, ss, &b);
		a--; b--;
		if (ss[0] == '<') lose[b].push_back(a);
		else win[b].push_back(a);
	}
	if (canwin()) printf("WYGRANA\n");
	else if (candraw()) printf("REMIS\n");
	else printf("PRZEGRANA\n");
}

int main() {
	int tt;
	scanf("%d", &tt);
	while (tt--) test();
	return 0;
}