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
62
63
64
65
66
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>

#define MAX_N 100001
#define BUFSIZE MAX_N*sizeof(int)

#define LOSS "PRZEGRANA"
#define WIN "WYGRANA"
#define DRAW "REMIS"

using namespace std;

int main(void) {
	int t;
	cin >> t;
	int *lewy = (int*)malloc(BUFSIZE);
	int *prawy = (int*)malloc(BUFSIZE);
	int *prawy_hit = (int*)malloc(BUFSIZE);
	for (int i = 0; i < t; i++){
		int n;
		int m;
		int nl = 0;
		int np = 0;
		cin >> n >> m;
		memset(lewy, 0, BUFSIZE);
		memset(prawy, 0, BUFSIZE);
		memset(prawy_hit, 0, BUFSIZE);
		
		for(int j = 0; j < m; j++){
			int l, p;
			char z;
			cin >> l >> z >> p;
			if (z == '>'){
				lewy[l]++;
				if (lewy[l] == 1)
					nl++;
				prawy_hit[p]++;
			} else {
				prawy[p]++;
				if (prawy[p] == 1)
					np++;
			}
		}
		if (np == n)
			cout << LOSS << endl;
		else if (nl < n)
			cout << DRAW << endl;
		else {
			bool win = false;
			for (int k = 1; k <= n; k++)
				if (prawy_hit[k] == n) {
					cout << WIN << endl;
					win = true;
					break;
				}
			if (!win)
				cout << DRAW << endl;
		}
	}
	free(lewy);
	free(prawy);
	free(prawy_hit);
	return 0;
}