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
#include <iostream>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main()
{
	iostream::sync_with_stdio(false);
	cin.tie(NULL);
	int32_t t;
	cin >> t;
	while (t-- > 0)
	{
		int32_t n, m;
		cin >> n >> m;
		unordered_set<int32_t> winB;
		unordered_map<int32_t, int32_t> winA;

		for (int32_t i = 0; i < m; ++i)
		{
			int32_t b;
			char w;
			cin >> b >> w >> b;
			if (w == '>')
			{
				if (winA.count(b) == 0) winA.insert(make_pair(b, 0));
				winA[b] = winA[b] + 1;
			}
			else if (winB.count(b) == 0)
			{
				winB.insert(b);
			}
		}

		if (winB.size() == n) cout << "PRZEGRANA" << endl;
		else
		{
			bool found = false;
			for (auto i = winA.begin(); i != winA.end(); ++i)
			{
				if (i->second == n)
				{
					cout << "WYGRANA" << endl;
					found = true;
					break;
				}
			}
			if (!found)
			{
				cout << "REMIS" << endl;
			}
		}
	}

	return 0;
}