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
92
93
94
95
96
97
98
#include <iostream>    
#include <algorithm>    
#include <vector> 
#include <cmath>
using namespace std;

struct Deck {
	int n;
	vector<int> w;
	Deck(int n) : n(n) {}
	bool operator<( const Deck& val ) const { 
        return w.size() > val.w.size(); 
   }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,t,a,b;
	char c;
	cin >>  t;
	for(int i=0; i<t; i++) {
		cin >> n >> m;
		vector<Deck> aa;
		vector<Deck> bb;		
		for(int j=0; j<n; j++) {
			Deck *d = new Deck(j);
			d->n = j;
			aa.push_back(*d);
			bb.push_back(*d);
		}
		
		  
		for(int j=0; j<m; j++) {
			//cout << "1" << endl;
			cin >> a >> c >> b;
			if(c == '>') {
				aa[a-1].w.push_back(b-1);						
			} else {
				bb[b-1].w.push_back(a-1);
			}
		}
		
		std::sort(aa.begin(), aa.end());
		std::sort(bb.begin(), bb.end());
		
	/*	for(int j=0; j<aa.size(); j++) {
			cout << "A " << aa[j].n << " " << aa[j].w.size() << endl;
		}
		for(int j=0; j<bb.size(); j++) {
			cout << "B " <<  bb[j].n << " " << bb[j].w.size() << endl;
		}*/
	//	cout << aa.size() << " " << bb.size() << endl;
		/*while(aa.size() > 1 && bb.size() > 1) {
			aa.erase(aa.begin());
			bb.erase(bb.begin());
			cout << aa.size() << " " << bb.size() << endl;
		}*/
		
		//cout << " 3 " << endl;
		Deck aD = aa[aa.size() - 1];
		Deck bD = bb[bb.size() - 1];
		cout << aD.w.size() << " " << bD.w.size() << endl;
		if(aD.w.size() == 0 && bD.w.size() == 0) {
			cout << "REMIS\n";
		} else if(aD.w.size() > 0 && bD.w.size() == 0) {
			cout << "WYGRANA\n";
		} else if(aD.w.size() == 0 && bD.w.size() > 0) {
			cout << "PRZEGRANA\n";
		} else {
			bool af = false;
			bool bf = false;
			for(int j=0; j<aD.w.size(); j++) {
				if(aD.w[j] == bD.n) {
					af = true;
					break;
				}
			}
			
			for(int j=0; j<bD.w.size(); j++) {
				if(bD.w[j] == aD.n) {
					bf = true;
					break;
				}
			}
			
			if(af && bf) {
				cout << "REMIS\n";
			} else if(af) {
				cout << "WYGRANA\n";
			} else {
				cout << "PRZEGRANA\n";
			}
		}
	}
	
	return 0;
}