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
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int i, t, n, m, a, b, win[100001], lose[100001];
char dir;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n,&m);
    memset(win+1, 0, n*sizeof(int));
    memset(lose+1, 0, n*sizeof(int));
    for (i=0; i<m; i++) {
      scanf("%d %c %d", &a,&dir,&b);
      if (dir == '>') lose[b]++; else win[b]++;
    }
    bool winning = false, losing = true;
    for (i=1; i<=n; i++)
      if (lose[i] == n)
        winning = true;
      else if (!win[i])
        losing = false;
    if (winning) printf("WYGRANA\n");
    else if (losing) printf("PRZEGRANA\n");
    else printf("REMIS\n");
  }
  return 0;
}