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
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 200100;
int n, m, T, a, b;
char tp;
int outB[maxn], inB[maxn];

int main() 
{
	scanf("%d", &T);
	FOR(z, 1, T)
	{
		scanf("%d%d", &n, &m);
		FOR(i, 1, n) outB[i] = 0, inB[i] = 0;
		FOR(i, 1, m)
		{
			scanf("%d %c %d", &a, &tp, &b);
			if (tp == '>') inB[b]++;
			else outB[b]++;
		}
		bool wa = 0, wb = 1;
		FOR(i, 1, n)
		  if (inB[i] == n) wa = 1;
		
		FOR(i, 1, n)
		  if (!outB[i]) wb = 0;
		  
		if (wa) puts("WYGRANA");
		else if (wb) puts("PRZEGRANA");
		else puts("REMIS");
	}
}