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
66
67
68
69
70
//Karol Kaszuba

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double D;
typedef long double LD;
typedef vector<PII> VII;
typedef unordered_set<int> USI;
typedef unordered_set<LL> USLL;

#define FOR(i,x,y) for(auto i=(x);i<=(y);++i)
#define REP(i,x) FOR(i,0,(x)-1)
#define FORD(i,x,y) for(auto i=(x);i>=(y);--i)
#define VAR(i,c) __typeof(c) i=(c)
#define FORE(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define SIZE(c) (int)((c).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define EB emplace_back
#define IN insert
#define ER erase
#define MP make_pair
#define ST first
#define ND second
#define IOSYNC ios_base::sync_with_stdio(0)
#define FREOPEN(f) freopen(f, "r", stdin),freopen(f, "w", stdout)

void jebaj() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v(n), w(n);
	REP(i, m) {
		int a, b;
		string s;
		cin >> a >> s >> b;
		a--;
		b--;
		if (s[0] == '<') {
			v[b].PB(a);
		} else {
			w[b].PB(a);
		}
	}
	REP(i, n) if (SIZE(w[i]) == n) {
		cout << "WYGRANA\n";
		return;
	}
	int a = 0;
	REP(i, n) a += (!v[i].empty());
	if (a == n) {
		cout << "PRZEGRANA\n";
		return;
	}
	cout << "REMIS\n";
	return;
}

int main() {
	IOSYNC;
	
	int t;
	cin >> t;
	while(t--) jebaj();
	return 0;
}