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
#include<cstdio>
#include<vector>

typedef std::vector<int> vi;
typedef vi::iterator vii;

vi T[200001];

int main() {
	int t;
	scanf("%d", &t);
	while(t--) {
		int n, m;
		scanf("%d %d", &n, &m);
		for (int i = 0; i < m; i++) {
			int u, v;
			char c;
			scanf("%d %c %d", &u, &c, &v);
			if (c == '<') {
				T[n + v-1].push_back(u-1);
			} else {
				T[u-1].push_back(n + v-1);
			}
		}
		
		
		bool win = true;
		bool lose = true;
		for (int i = 0; i < n; i++) {
			if (T[i].empty()) {
				win = false;
			}
			if (T[i+n].empty()) {
				lose = false;
			}
		}
		
		if (win) {
			printf("WYGRANA\n");
		} else if (lose) {
			printf("PRZEGRANA\n");
		} else {
			printf("REMIS\n");
		}
		
		
		for (int i = 0; i < 2 * n; i++) {
			T[i].clear();
		}
	}
	return 0;
}