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
// kar.cpp : Defines the entry point for the console application.
//

#include <cstdio>
#include <vector>

using namespace std;


int get_num_of_non_zero(const vector<int> &v)
{
	int res = 0;
	for(size_t i=0; i < v.size(); i++) {
		if(v[i] > 0)
			res++;
	}
	return res;
}

int get_num_of_n(const vector<int> &v)
{
	int res = 0;
	for(size_t i=0; i < v.size(); i++) {
		if(v[i] == v.size())
			res++;
	}
	return res;
}

int main(int argc, char* argv[])
{
	int TEST_NUM;
	scanf("%d", &TEST_NUM);
	for(int the_test = 0;  the_test < TEST_NUM;  the_test++) {
		int N, M;
		scanf("%d%d", &N, &M);
		vector<int> deg_2_in(N, 0);
		vector<int> deg_2_out(N, 0);
		for(int k=0; k<M; k++) {
			int u, v;
			char c;
			scanf("%d %c %d", &u, &c, &v);
			int _1_idx = u-1;
			int _2_idx = v-1;
			if(c == '<') {
				deg_2_in[_2_idx]++;
			} else {
				deg_2_out[_2_idx]++;
			}
		}
		int num_of_non_zero_in_2 = get_num_of_non_zero(deg_2_in);
		int num_of_n_in_2 = get_num_of_n(deg_2_out);
		if(num_of_n_in_2 > 0)
			printf("WYGRANA\n");
		else if(num_of_non_zero_in_2 == N)
			printf("PRZEGRANA\n");
		else
			printf("REMIS\n");
	}
	return 0;
}