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

const int N = 1e5 + 3;
int T, n, m, A[N], B[N];

inline bool Win() {
  for (int i = 1; i <= n; ++i)
    if (A[i] == n) return true;
  return false;
}

inline bool Lose() {
  for (int i = 1; i <= n; ++i)
    if (B[i] == 0) return false;
  return true;
}

int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) A[i] = B[i] = 0;
    for (int i = 1; i <= m; ++i) {
      int a, b;
      char c;
      scanf("%d %c %d", &a, &c, &b);
      if (c == '>') ++A[b];
      else ++B[b];
    }
    if (Win()) puts("WYGRANA");
    else if (Lose()) puts("PRZEGRANA");
    else puts("REMIS");
  }
  return 0;
}