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

typedef unsigned int uint_t;

const static uint_t MAX_T = 20;
const static uint_t MAX_N = 100000;
bool winA[MAX_T][MAX_N];
bool winB[MAX_T][MAX_N];

int main() {
	uint_t t, n, m, a, b;
	uint_t winANum, winBNum;
	char w;
	scanf("%u", &t);
	for (uint_t i = 0; i < t; ++i) {
		winANum = winBNum = 0;
		scanf("%u %u", &n, &m);
		for (uint_t j = 0; j < m; ++j) {
			scanf("%u %c %u", &a, &w, &b);
			if (w == '>') {
				if (!winA[i][a - 1]) {
					winA[i][a - 1] = true;
					winANum += 1;
				}
			} else {
				if (!winB[i][b - 1]) {
					winB[i][b - 1] = true;
					winBNum += 1;
				}
			}
		}
		if (winANum >= n)
			printf("WYGRANA\n");
		else if (winBNum >= n)
			printf("PRZEGRANA\n");
		else
			printf("REMIS\n");
	}
	return 0;
}