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
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<vector>
using namespace std;

typedef long long LL;
typedef long double LD;

#define dprintf(...) fprintf(stderr, __VA_ARGS__)

int cond = 1;
#define DB(X) {if(cond){cerr<<"Line:"<<__LINE__<<", "<<#X<<" = "<<X<<endl;}}

string solve() {
	int n, m; cin >> n >> m;
	vector<bool> a(n+5, false);
	vector<int> b(n+5, 0);
	for(int i = 0; i < m; ++i) {
		int x, y;
		char c;
		cin >> x >> c >> y;
		if (c == '<') {
			a[y] = true;
		}
		else {
			b[y]++;
		}
	}
	bool all = true;
	bool inter = false;
	for(int i = 1; i <= n; ++i) {
		all = all && a[i];
		if (b[i] == n) {
			inter = true;
		}
	}
	if (all) {
		return "PRZEGRANA";
	}
	if (inter) {
		return "WYGRANA";
	}
	return "REMIS";
}

int main() {
	int t; cin >> t;
	for(int x = 1; x <= t; ++x){
		cout << solve() << endl;//result 
	}
	return 0;
}