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

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  cin >> t;

  while (t > 0) {
    --t;

    int n, m;
    cin >> n >> m;

    vector<int> second_wins(n);
    vector<int> second_loses(n);
    for (int i = 0; i < m; ++i) {
      int a, b;
      char r;
      cin >> a >> r >> b;
      --a;
      --b;
      if (r == '<') ++second_wins[b];
      else ++second_loses[b];
    }

    bool first_can_win = false;
    bool first_can_draw = false;
    for (int i = 0; i < n; ++i) {
      if (second_loses[i] == n) first_can_win = true;
      else if (second_wins[i] == 0) first_can_draw = true;
    }

    if (first_can_win) cout << "WYGRANA\n";
    else if (first_can_draw) cout << "REMIS\n";
    else cout << "PRZEGRANA\n";
  }

  return 0;
}