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
#include <algorithm>
#include <iostream>
#include <vector>


typedef unsigned int smallnum;
typedef unsigned char xsnum;


// Some flags
const int WIN_FLAG = 1;
const int LOSE_FLAG = -1;
const int DRAW_FLAG = 0;


smallnum solve_case() {
  smallnum n, m;
  scanf("%u %u\n", &n, &m);

  // For storing the data
  std::vector<xsnum> second_is_hitting(n);
  std::vector<smallnum> second_is_hit_counter(n);

  for (smallnum i = 0; i < m; i++) {
    smallnum a, b;
    char w;
    scanf("%u %c %u\n", &a, &w, &b);

    switch (w) {
    case '<':
      second_is_hitting[b-1] = 1;
      break;
    case '>':
      second_is_hit_counter[b-1]++;
      break;
    }
  }

  bool are_all_hitting = (
                          std::find(second_is_hitting.begin(),
                                    second_is_hitting.end(), 0)
                          == second_is_hitting.end()
                          );

  if (are_all_hitting) {
    return LOSE_FLAG;
  }

  bool is_one_hit_by_all = (
                            std::find(second_is_hit_counter.begin(), second_is_hit_counter.end(), n)
                            != second_is_hit_counter.end()
                            );

  if (is_one_hit_by_all) {
    return WIN_FLAG;
  }

  return DRAW_FLAG;
}


int main() {
  // Step 1. Get the data
  smallnum t;
  scanf("%u\n", &t);

  // Solve t cases
  for (smallnum i = 0; i < t; i++) {
    int case_result = solve_case();

    switch (case_result) {
    case WIN_FLAG:
      printf("WYGRANA\n");
      break;
    case LOSE_FLAG:
      printf("PRZEGRANA\n");
      break;
    case DRAW_FLAG:
      printf("REMIS\n");
      break;
    }
  }

  return 0;
}