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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int tw[100000], tp[100000];

int main() {
	int t;
	scanf("%d", &t);
	REP(tt,t) {
		int n, m;
		scanf("%d%d", &n, &m);
		REP(i,n) tw[i] = tp[i] = 0;
		REP(j,m) {
			int b;
			char w;
			scanf("%*d %c%d", &w, &b);
			--b;
			if (w == '<') ++tw[b];
			else ++tp[b];
		}
		bool wy = 0;
		REP(i,n) if (tp[i] == n) {
			wy = 1;
			break;
		}
		if (wy) {
			printf("WYGRANA\n");
			continue;
		}
		bool rem = 0;
		REP(i,n) if (!tw[i]) {
			rem = 1;
			break;
		}
		if (rem) printf("REMIS\n");
		else printf("PRZEGRANA\n");
	}
}