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
#include <bits/stdc++.h>

using namespace std;

typedef int game_result;

const int LOSE = 0;
const int DRAW = 1;
const int WIN = 2;

struct relation {
    int deck_a, deck_b;
    game_result a_result;
};

string solve(int n, const vector<relation>& relations) {
    vector<game_result> a_decks(n, LOSE);

    vector<int> win_against_b_count(n, 0);
    vector<char> can_lose_against_b(n, false);

    for (const relation& r: relations) {
        if (r.a_result == WIN) {
            win_against_b_count[r.deck_b]++;
        }

        if (r.a_result == LOSE) {
            can_lose_against_b[r.deck_b] = true;
        }
    }

    for (int b_deck = 0; b_deck < n; b_deck++) {
        if (win_against_b_count[b_deck] == n) {
            return "WYGRANA";
        }
    }

    if (find(can_lose_against_b.begin(), can_lose_against_b.end(), false) == can_lose_against_b.end()) {
        return "PRZEGRANA";
    }

    return "REMIS";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    for (int test = 0; test < t; test++) {
        int n, m;
        cin >> n >> m;
        
        vector<relation> relations(m);
        for (int i = 0; i < m; i++) {
            int a, b;
            char w;
            cin >> a >> w >> b;
            a--, b--;

            relations[i].deck_a = a;
            relations[i].deck_b = b;
            relations[i].a_result = (w == '>' ? WIN : LOSE);
        }

        cout << solve(n, relations) << endl;
    }
}