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
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define mp make_pair

#define REP(i,n) for (int i=0,___=(n); i<___; ++i)
#define FOR(i,a,b) for (int i=(a),___=(b); i<=___; ++i)
#define FORD(i,a,b) for (int i=(a),___=(b); i>=___; --i)

int read() { int n; scanf("%d", &n); return n; }
ll readl() { ll n; scanf("%lld", &n); return n; }
char readc() { static char s[32]; scanf("%s", s); return *s; }


int solve() {
	int n = read();
	int m = read();
	vector<int> firstCnt(n, 0);
	vector<bool> secondEmpty(n, true);
	REP(i, m) {
		read(); //int x = read() - 1;
		char c = readc();
		int y = read() - 1;
		if (c == '>') ++firstCnt[y];
		else secondEmpty[y] = false;
	}
	REP(i, n) if (firstCnt[i] == n) return 1;
	REP(i, n) if (secondEmpty[i]) return 0;
	return -1;
}



int main() {
	int t = read();
	while (t--) {
		int res = solve();
		printf("%s\n", res > 0 ? "WYGRANA" : res < 0 ? "PRZEGRANA" : "REMIS");
	}
	return 0;
}