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
#include <stdio.h>

int G[200000 + 5];
int L[200000 + 5];

bool find(int t[], int n, int x) {
  for (int i = 1; i <= n; ++i) {
    if (t[i] == x) {
      return true;
    }
  }
  return false;
}

int main() {
  int t;
  char buf[257];

  fgets(buf, sizeof buf, stdin);
  sscanf(buf, "%d", &t);
  for (int i = 0; i < t; ++i) {
    int n, m;
    fgets(buf, sizeof buf, stdin);
    sscanf(buf, "%d %d", &n, &m);
    for (int j = 0; j < m; ++j) {
      int a, b;
      char w;
      fgets(buf, sizeof buf, stdin);
      sscanf(buf, "%d %c %d", &a, &w, &b);
      if (w == '>') {
        ++G[b];
      } else if (w == '<') {
        ++L[b];
      }
    }
    if (find(G, n, n)) {
      printf("WYGRANA\n");
    } else if (find(L, n, 0)) {
      printf("REMIS\n");
    } else {
      printf("PRZEGRANA\n");
    }
    for (int j = 0; j <= n; ++j) {
      G[j] = L[j] = 0;
    }
  }
  return 0;
}