1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "bits/stdc++.h"
using namespace std;

int main(){
  int t, n, m, a, b;
  string w;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while(t--){
    cin >> n >> m;
    vector<int> gt(n, 0), lt(n, 0);
    while(m--){
      cin >> a >> w >> b;
      --a; --b;
      if(w == ">") ++gt[b];
      if(w == "<") ++lt[b];
    }
    if(find(gt.begin(), gt.end(), n) != gt.end()) cout << "WYGRANA\n";
    else if(find(lt.begin(), lt.end(), 0) != lt.end()) cout << "REMIS\n";
    else cout << "PRZEGRANA\n";

  }
}