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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;

pair<pair<int, int>, int> a[100010], b[100010];
int c[200010], d[200010], e[100010];
char x[200010];

int main(){
	int m, n,t, w;
	scanf("%d", &t);
	for (int i = 1; i <= t; i++){
		scanf("%d %d", &m, &n);
		for (int j = 1; j <= m; j++){
			e[j] = 1;
			a[j] = make_pair(make_pair(0, m), j);
			b[j] = make_pair(make_pair(0, m), j);
		}
		for (int j = 1; j <= n; j++){
			scanf("%d %c %d", &c[j], &x[j], &d[j]);
			if (x[j] == '<')
				b[d[j]].first.first++;
			else
				a[c[j]].first.first++;
			b[d[j]].first.second--;
			a[c[j]].first.second--;
		}
		sort(a + 1, a + m + 1);
		sort(b + 1, b + m + 1);
		w = 2;
		for (int j = 1; j <= n; j++){
			if (d[j] == b[1].second){
				if (x[j] == '>'){
					e[c[j]] = 2;
				}
				else
					e[c[j]] = 0;
			}
		}
		int t = 1;
		while ((a[1].first.first == a[t].first.first) && (a[1].first.second == a[t].first.second)){
			w = min(w, e[a[t].second]);
			t++;
		}
		if (w == 1){
			printf("REMIS\n");
		}
		else{
			if (w == 2){
				printf("WYGRANA\n");
			}
			else{
				printf("PRZEGRANA\n");
			}
		}
	}
	system("pause");
}