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 <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while(T--) {
    int n, m;
    cin >> n >> m;
    
    vector<int> br(n+1), bl(n+1), dr(n+1, n);
    dr[0]=0;
    
    while(m--) {
      int l, r;
      string x;
      cin >> l >> x >> r;
      if (x == ">") {
        ++br[r];
      } else {   
        ++bl[l];     
        --dr[r];
      }
    }
    
    int mr = *max_element(br.begin(), br.end());
    int ml = *max_element(bl.begin(), bl.end());
    int mdr = *max_element(dr.begin(), dr.end());

    if (mr == n) {
      cout << "WYGRANA";
    } else if (ml == n) {
      cout << "PRZEGRANA";
    } else if (mdr == n) {
      cout << "REMIS";
    } else {
      cout << "PRZEGRANA";
    }
    
    cout << endl;
  }
}