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
#include<cstdio>
#include<algorithm>
#include<utility>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<iostream>

// macros

#define FORE(c, a, b) for(int c=a; c<= int(b); ++c)
#define FORD(c, a, b) for(int c=a; c>= int(b); --c)
#define FORIT(it, cont, cont_t) for(cont_t::iterator it = cont.begin(); it != cont.end(); ++it)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ALL(a) a.begin(), a.end() 
#define PR(n) printf("%d ", (int) (n)) 
#define PRL(n) printf("%lld ", (ll) (n)) 
#define SC(n) scanf("%d", &n);
#define SC2(n, m) scanf("%d%d", &n, &m);

#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define itr iterator

#define dbg if(1)
#define prd dbg printf

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef vector<pi> vii;
typedef vector<vi> vvi;

const int NMAX = 1<<20;

int n, m, t;
int x, y, out[NMAX], in[NMAX];
char sign;
bool bWin, bLoose;

int main() {
  SC(t);
  REP(it, t) {
    SC2(n, m);
    REP(i, n+1)
      out[i] = in[i] = 0;
    REP(im, m) {
      scanf("%d%c%c%d", &x, &sign, &sign, &y);
      //printf("%d %c %d", x, sign, y);
      if(sign == '<')
        out[y]++;
      else
        in[y]++;
    }
    bWin = true;
    bLoose = false;
    FORE(i, 1, n) {
      if(out[i] == 0)
        bWin = false;
      if(in[i] == n)
        bLoose = true;
    }
    if(bWin)
      printf("PRZEGRANA\n");
    else if(bLoose)
      printf("WYGRANA\n");
    else printf("REMIS\n");
  }
  return 0;
}