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

using namespace std;

const int MAX_N = 100001;
int t[MAX_N];
int t2[MAX_N];
int y[MAX_N];
int y2[MAX_N];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  
  for(int i = 0; i <= n; i++)
    t[i] = t2[i] = y[i] =  y2[i] = 0;
  
  for(int i = 0; i < m; i++) {
    int a, b;
	char c;
	scanf("%d %c %d", &a, &c, &b);
	if(c=='>') t[a]++; else t2[a]++;
	if(c=='<') y[b]++; else y2[b]++;
  }
  
  int cov1 = 0, cov11 = 0;
  int cov2 = 0, cov22 = 0;
  for(int i = 1; i <= n; i++) {
	if (y2[i] > 0) cov1 = max(cov1, y2[i]);
	if (y[i] > 0) cov2++;
	if (y2[i] > 0) cov22++;
  }
 
  int res = 0;
  if(cov1 == n) res = 1; 
  else if(cov2 == n) res = -1;
  
  if(n == 1) {
    if (cov1 == 1) res = 1;
	else res = -1;
  }
  string s = "";
  if(res == 1) s = "WYGRANA";
  if(res == -1) s = "PRZEGRANA";
  if(res == 0) s = "REMIS";
  printf("%s\n", s.c_str());
}
int main(int args, char* argv[]) {

  int t;
  scanf("%d", &t);
  
  for(int i = 0; i < t; i++)
    solve();

  return 0;
}