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
85
86
87
88
89
90
91
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <utility>
#include <queue>
#include <list>
#include <iomanip>
#include <set>

#define PI 3.14159265

using namespace std;

int n,m;
vector<list<int > > fail_bajtka, fail_bitka;
bool win, loose;

inline void read_input()
{
  cin >> n >> m;
  fail_bajtka.resize(n);
  fail_bitka.resize(n);
  int bajtka,bitka;
  char w;
  for (int i = 0; i < m; ++i)
  {
    cin >> bajtka >> w >> bitka;
    if (w == '<') fail_bajtka[bajtka-1].push_back(bitka-1);
    else          fail_bitka[bitka-1].push_back(bajtka-1);
  }
}

inline void print_output()
{
  if (win)
    cout << "WYGRANA" << endl;
  else if (loose)
    cout << "PRZEGRANA" << endl;
  else
    cout << "REMIS" << endl;
}

inline void clear_data()
{
  for (int i = 0; i < n; ++i)
  {
    fail_bitka[i].clear();
    fail_bajtka[i].clear();
  }
}


bool check_win(vector<list<int > >& beating)
{
  for (int i = 0; i < n; ++i)
    if (beating[i].size() == n)
      return true;
  return false;
}

void solve()
{
  win = false; loose = false;
  // INV: win NAND loose
  win = check_win(fail_bitka);
  loose = check_win(fail_bajtka);
}


int main(int argc, const char *argv[])
{
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i)
  {
    read_input();
    solve();
    print_output();
    clear_data();
  }
  return 0;
}