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
#include <cstdio>
#include <vector>
using namespace std;

const int MAX = 100010;

int n, m;
int conquered_by_bajtek[MAX];
bool is_conquering[MAX];

void find_and_print_answer() {
	for(int i = 1; i <= n; i++) {
		if(conquered_by_bajtek[i] == n) {
			printf("WYGRANA\n");
			return;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(!is_conquering[i]) {
			printf("REMIS\n");
			return;
		}
	}
	printf("PRZEGRANA\n");
}

void solve() {
	int a, b;
	char w;
	scanf("%d%d", &n, &m);
	while(m--) {
		scanf("%d %c %d", &a, &w, &b);
		switch(w) {
			case '<':
				is_conquering[b] = true;
				break;
			case '>':
				conquered_by_bajtek[b]++;
		}
	}
	find_and_print_answer();
	for(int i = 1; i <= n; i++) {
		is_conquering[i] = false;
		conquered_by_bajtek[i] = 0;
	}
}

int main() {
	int t;
	scanf("%d", &t);
	while(t--)
		solve();
}