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
#include <cstdio>
#include <unordered_set>
#include <vector>

void get_winner() {
	unsigned int n;
	unsigned int m;
	int deck1;
	int deck2;
	char dir;
	bool win;

	// Decks of player 2 that can possibly win
	std::unordered_set<int> winning_decks;
	// How many decks of player 1 are better than deck i of player 2
	std::vector<unsigned int> how_many_better;

	std::scanf("%u %u", &n, &m);

	how_many_better.resize(n, 0);

	for(unsigned int i = 0; i < m; ++i) {
		std::scanf("%d %c %d", &deck1, &dir, &deck2);
		// Another deck of player 1 is better than deck2
		if(dir == '>') {
			++how_many_better[deck2 - 1];
		}
		// Deck of player 2 can possibly win
		else {
			winning_decks.insert(deck2);
		}
	}

	// If every deck of player 2 can win over a deck of player 1
	// player 2 wins
	if(winning_decks.size() == n) {
		std::printf("PRZEGRANA\n");
	}
	// Otherwise player 1 can always at leas draw
	// (by removing all but a non-wining deck of player 2)
	else {
		win = false;
		for(auto &hmb : how_many_better) {
			// Player 1 can win
			if(hmb == n) {
				win = true;
				std::printf("WYGRANA\n");
				break;
			}
		}
		// Player 1 cannot win but can draw
		if(!win) {
			std::printf("REMIS\n");
		}
	}
}

int main() {
	int t;

	std::scanf("%d", &t);

	while(t-- > 0) {
		get_winner();
	}
	
	return 0;
}