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

int main() {
  int t;
  scanf("%d", &t);
  while(t--) {
    int n, m;
    scanf("%d", &n); scanf("%d", &m);
    vector<vector<int>> Ai(n+1), Ao(n+1), Bi(n+1), Bo(n+1);
    for(int i=0; i<m; ++i) {
      int a, b;
      scanf("%d", &a);
      getchar();
      char c = getchar();
      scanf("%d", &b);
      //printf("%d%c%d\n", a, c, b);
      if(c == '>') {
        Ao[a].push_back(b);
        Bi[b].push_back(a);
      } else if(c == '<') {
        Bo[b].push_back(a);
        Ai[a].push_back(b);
      }
    }
    int bo=0, bi=0;
    for(int i=1; i<=n; ++i) {
      if(Bo[i].size()) ++bo;
      if(Bi[i].size() == n) ++bi;
    }
    if(bo == n) {
      puts("PRZEGRANA");
      continue;
    }
    if(bi) {
      puts("WYGRANA");
      continue;
    }
    puts("REMIS");
  }
}