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
#include <iostream>
using namespace std;


#include "stdio.h"

#define	NN	100000

int		 n, m;
int		 aa[NN+1], bb[NN+1];

int		 a, b;
char	 dir[8];

void calc()
{
	int	 i, bA, bB;
	
	scanf("%d%d", &n, &m);
	
	for (i=1; i<=n; i++) aa[i]	= 0;
	for (i=1; i<=n; i++) bb[i]	= 0;
	
	bA	= 0;
	bB	= 0;
	
	for (i=0; i<m; i++)
	{
		scanf("%d%s%d", &a, dir, &b);
		if (dir[0]=='>')
		{
			aa[b]++;
			if (aa[b]==n)
				bA++;
		}
		else if (dir[0]=='<')
		{
			if (bb[b]==0)
				bB++;
				
			bb[b]++;
		}
	}
	
	if (bA>0)
		printf("%s\n", "WYGRANA");
	else if (bB==n)
		printf("%s\n", "PRZEGRANA");
	else
		printf("%s\n", "REMIS");
}

int main() 
{
	int	 t;
	
	scanf("%d", &t);
	while (t--)
		calc();
		
	return 0;
}