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

const int max_n = 1000000;

int n, m;
std::vector<int> A[max_n];
std::vector<int> B[max_n];

std::string gogo() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    A[i].clear();
    B[i].clear();
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    char c;
    scanf ("%d %c %d", &u, &c, &v);
    --u;
    --v;
    if (c == '>') {
      B[v].push_back(u);
    } else {
      A[v].push_back(u);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (B[i].size() == n) {
      return "WYGRANA";
    }
  }
  for (int i = 0; i < n; ++i) {
    if (A[i].size() == 0) {
      return "REMIS";
    }
  }
  return "PRZEGRANA";
}

int main() {
  int t;
  scanf ("%d", &t);
  while (t--) {
    printf("%s\n", gogo().c_str());;
  }
  return 0;
}