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
#include <cstdio>
#include <vector>
using namespace std;

int main() {
  int t;
  scanf("%d", &t);
  while(t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> wins(n);
    vector<bool> loses(n);
    for (int i = 0; i < m; ++i) {
      int x, y;
      char c;
      scanf("%d %c %d", &x, &c, &y);
      --x; 
      --y;
      if (c == '<') {
        loses[y] = true;
      }
      else {
        ++wins[y];
      }
    }
    bool win = false, lost = true;
    for (int i = 0; i < n; ++i) {
//      printf("%d %d\n", (int) loses[i], wins[i]);
      if (!loses[i])
        lost = false;
      if (wins[i] == n)
        win = true;
    }
    if (lost)
      printf("PRZEGRANA\n");
    else if (win)
      printf("WYGRANA\n");
    else
      printf("REMIS\n");
  }

  return 0;
}