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

const int N = 100000 + 10;

int n, x[N], y[N];

int main() {
  int tcase;
  for (scanf("%d", &tcase); tcase--;) {
    int m;
    scanf("%d%d", &n, &m);
    std::fill(x + 1, x + n + 1, 0);
    std::fill(y + 1, y + n + 1, 0);
    while (m--) {
      int a, b;
      char op;
      scanf("%d %c%d", &a, &op, &b);
      if (op == '<') ++x[b]; else ++y[b];
    }
    if (std::count(y + 1, y + n + 1, n)) {
      puts("WYGRANA");
      continue;
    }
    if (std::count(x + 1, x + n + 1, 0)) {
      puts("REMIS");
      continue;
    }
    puts("PRZEGRANA");
  }
  return 0;
}