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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <strings.h>

#define zero(x) bzero((x), sizeof(x))

int solve(int n, int m) {
  int cp[n], cm[n], rp[n], rm[n];
  int win = 1, tie = 1, lose = 1, i, j, k, p, q;

  if (!m) return 0;

  zero(cp);
  zero(cm);
  zero(rp);
  zero(rm);

  for (i = 0; i < m; ++i) {
    int a, b;
    char w;
    scanf("%d %c %d", &a, &w, &b);
    --a;
    --b;
    if (w == '<') {
      ++cm[b];
      ++rm[a];
    } else {
      ++cp[b];
      ++rp[a];
    }
  }

  for (i = 0; i < n; ++i) {
    if (cp[i] == n) return +1;
    if (rm[i] == n) return -1;
    if (!cm[i]) lose = 0;
    if (!rp[i]) win = 0;
  }

  if (!win && !lose) return 0;

  j = k = p = q = 0;
  for (i = 0; i < n; ++i) {
    if (n - cm[i] >= 2) ++j;
    if (cp[i] >= 2) ++k;
    if (cp[i] + cm[i] < n) ++p;
    if (cm[i]) ++q;
  }

  if (!j) return -1;
  if (!k) win = 0;
  if (!p) tie = 0;
  if (!q) lose = 0;

  if (lose) return -1;
  if (tie) return 0;
  return +1;
}

int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    switch (solve(n, m)) {
      case +1: printf("WYGRANA\n");   break;
      case  0: printf("REMIS\n");     break;
      case -1: printf("PRZEGRANA\n"); break;
    }
  }
  return 0;
}