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
#include <cinttypes>
#include <cstdio>
#include <cstring>

using namespace std;

uint32_t rWinCnt[100000];
uint32_t rLoseCnt[100000];

void testCase()
{
	uint32_t n, m;
	scanf("%u %u", &n, &m);

	memset(rWinCnt, 0, sizeof(uint32_t) * n);
	memset(rLoseCnt, 0, sizeof(uint32_t) * n);

	for (uint32_t i = 0; i < m; ++i) {
		uint32_t a, b;
		char w;
		scanf("%u %c %u", &a, &w, &b);
		if (w == '<') {
			rWinCnt[b - 1]++;
		} else {
			rLoseCnt[b - 1]++;
		}
	}

	for (uint32_t i = 0; i < n; ++i) {
		if (rLoseCnt[i] == n) {
			printf("WYGRANA\n");
			return;
		}
	}

	for (uint32_t i = 0; i < n; ++i) {
		if (rWinCnt[i] == 0) {
			printf("REMIS\n");
			return;
		}
	}

	printf("PRZEGRANA\n");
}

int main(int argc, const char* argv[])
{
	uint32_t tcnt;
	scanf("%u", &tcnt);

	for (uint32_t t = 0; t < tcnt; ++t) {
		testCase();
	}

	return 0;
}