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

int main() {
  int z;
  scanf("%d", &z);
  while (z--) {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> cnt_win(n, 0), not_fial(n, 1);
    while (m--) {
      int b;
      char c;
      scanf("%*d %c %d", &c, &b);
      b--;
      if (c == '<') {
        not_fial[b] = 0;
      } else {
        cnt_win[b]++;
      }
    }
    bool win = std::any_of(cnt_win.begin(), cnt_win.end(), [n](int c){return c == n;});
    bool tie = std::any_of(not_fial.begin(), not_fial.end(), [](int c){return c;});
    printf("%s\n", win ? "WYGRANA" : (tie ? "REMIS" : "PRZEGRANA"));
  }
  return 0;
}