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

using namespace std;

//int Lwins[100][100004];
//int Rwins[100][100004];
int Lins[20][100004];
int Rins[20][100004];
bool Lwins[20][100004];
bool Rwins[20][100004];
int main()
{
	int queries;
	scanf("%d", &queries);
	for (int q = 0; q < queries; q++)
	{
		int pairs, strongPairs;
		int maxL = 0, maxR = 0;
		int a, b;
		scanf("%d%d", &pairs, &strongPairs);
		char c;
		int LAttacking = 0, RAttacking = 0;
		for (int i = 0; i < strongPairs; i++)
		{
			scanf("%d %c %d", &a, &c, &b);
			if (c == '>')
			{
				if (!Lwins[q][a])
				{
					Lwins[q][a] = true;
					LAttacking++;
				}

				maxR = max(++Rins[q][b], maxR);
			}
			else
			{
				if (!Rwins[q][b])
				{
					Rwins[q][b] = true;
					RAttacking++;
				}
				maxL = max(++Lins[q][a], maxL);
			}
		}

		if (maxR == pairs)
		{
			printf("WYGRANA\n");
		}
		else if(maxL == pairs || RAttacking == pairs)
		{
			printf("PRZEGRANA\n");
		}
		else
		{
			printf("REMIS\n");
		}

	}

	return 0;
}