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
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Scanner;

public class kar {
  public static Scanner in;
  public static PrintWriter out;

  public static void setInput(InputStream in) {
    kar.in = new Scanner(in);
  }

  public static void setOutput(PrintStream out) {
    kar.out = new PrintWriter(new OutputStreamWriter(out));
  }

  public static void main(String[] args) throws Exception {
    try {
      Locale.setDefault(Locale.US);
    } catch (Exception e) {
    }
    if (in == null) {
      setInput(System.in);
    }
    if (out == null) {
      setOutput(System.out);
    }

    new kar().solve();
    out.flush();
  }

  int nextInt() {
    return in.nextInt();
  }

  String next() {
    return in.next();
  }
  
  void solve() throws Exception {
	  for (int i = nextInt(); i > 0; i--) {
		  solveSingle();
	  }
  }

   void solveSingle() throws Exception {
	int n = nextInt();
    int[] t1 = new int[n];
    int[] t2 = new int[n];
    boolean win1 = false;
    boolean win2 = false;
    for (int i = nextInt(); i > 0; i--) {
      int a = nextInt() - 1;
      boolean win = next().startsWith(">");
      int b = nextInt() - 1;
      if (win) {
    	  win1 |= ++t2[b] == n;
      } else {
    	  win2 = ++t1[a] == n;
      }
    }
    out.println(win1 ? "WYGRANA" : win2 ? "PRZEGRANA" : "REMIS");
  }
}