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
// joy code
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
template<typename T> ostream& operator<<(ostream& s, vector<T> t) {
    rep(i, 0, t.size()) s << (i ? " " : "") << t[i]; return s;
}
typedef long long ll;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> plus(n), minus(n);
    rep(i, 0, m) {
        int a, b;
        char c;
        cin >> a >> c >> b;
        a--, b--;
        if (c == '>') plus[b]++;
        else          minus[b]++;
    }
    bool loss = true, draw = true;
    rep(i, 0, n) {
        if (plus[i] == n) draw = false;
        if (minus[i] == 0) loss = false;
    }
    if (loss) cout << "PRZEGRANA" << endl;
    else if (draw) cout << "REMIS" << endl;
    else cout << "WYGRANA" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) solve();
}