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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

#define PB          push_back
#define ST          first
#define ND          second

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using VII = vector<PII>;
using LL = long long int;
using ULL = unsigned long long int;

int test_cases;

void InitAndSolve() {
  int n, m;
  scanf("%d %d", &n, &m);
  VI his_indeg(n + 1, 0);
  VI his_outdeg(n + 1, 0);
  int uin, vin;
  char cin;
  for (int i = 0; i < m; ++i) {
    scanf("%d %c %d", &uin, &cin, &vin);
    if (cin == '<') {
      ++his_outdeg[vin];
    } else if (cin == '>') {
      ++his_indeg[vin];
    }
  }

  bool all_his_outdegs_positive = true;
  for (int i = 1; i <= n; ++i) {
    if (his_outdeg[i] == 0) {
      all_his_outdegs_positive = false;
      break;
    }
  }
  if (all_his_outdegs_positive) {
    printf("PRZEGRANA\n");
    return;
  }

  bool he_has_losing_node = false;
  for (int i = 1; i <= n; ++i) {
    if (his_indeg[i] == n) {
      he_has_losing_node = true;
      break;
    }
  }
  if (he_has_losing_node) {
    printf("WYGRANA\n");
  } else {
    printf("REMIS\n");
  }
}

int main() {
  scanf("%d", &test_cases);
  for (int i = 0; i < test_cases; ++i) {
    InitAndSolve();
  }
  return 0;
}