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
67
68
#include <iostream>
#include <map>

using namespace std;

void runda() {
	std::map<pair<int, int>, bool> mapa;

	int n, m;
	char znak;
	int talia1, talia2;
	int tablica1[100000] = {};
	int tablica2[100000] = {};

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> talia1 >> znak >> talia2;
		talia1--;
		talia2--;
		if (znak == '>') {
			tablica1[talia1]++;
			tablica2[talia2]--;
			mapa[make_pair(talia1, talia2)] = true;
		}
		else {
			tablica1[talia1]--;
			tablica2[talia2]++;
			mapa[make_pair(talia1, talia2)] = false;
		}
	}

	int minimum1 = tablica1[0];
	int lokMinimum1 = 0;
	int minimum2 = tablica2[0];
	int lokMinimum2 = 0;
	for (int i = 1; i < n; i++) {
		if (tablica1[i] < minimum1) {
			minimum1 = tablica1[i];
			lokMinimum1 = i;
		}
		if (tablica2[i] < minimum2) {
			minimum2 = tablica2[i];
			lokMinimum2 = i;
		}
	}

	if (mapa.count(make_pair(lokMinimum1, lokMinimum2)) == 0) {
		cout << "REMIS" << endl;
	}
	else {
		if (mapa[make_pair(lokMinimum1, lokMinimum2)] == true)
			cout << "WYGRANA" << endl;
		else
			cout << "PRZEGRANA" << endl;
	}
}

int main()
{
	int t;
	cin >> t;

	while (t-- > 0)
		runda();

	return 0;
}