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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class kar {
	public static void main(final String[] args) throws Exception {
    	try (final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
	    	final String line = br.readLine();
	    	final int t = Integer.parseInt(line);
	    	
	    	for (int i = 0; i < t; i++) {
	    		final Set<Integer> firstWinning = new HashSet<Integer>();
		    	final Set<Integer> secondWinning = new HashSet<Integer>();
		    	
		    	final String cases = br.readLine();
	    		final String[] params = cases.split(" ");
	    		final int decks = Integer.parseInt(params[0]);
	    		final int pairs = Integer.parseInt(params[1]);
	    		for (int j = 0; j < pairs; j++) {
	    			final String pair = br.readLine();
	    			final String[] pairParams = pair.split(" ");
	    			
	    			final int first = Integer.parseInt(pairParams[0]);
	    			final int second = Integer.parseInt(pairParams[2]);
	    			if (pairParams[1].equals(">")) {
	    				firstWinning.add(first);
	    			} else {
	    				secondWinning.add(second);
	    			}
	    		}

	    		if (firstWinning.size() == decks) {
		    		System.out.println("WYGRANA");
		    	} else if (secondWinning.size() == decks) {
		    		System.out.println("PRZEGRANA");
		    	} else {
		    		System.out.println("REMIS");
		    	}
	    	}
    	}
	}
}