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
#include<string>
#include<stdio.h>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<bitset>
#define ll long long
#define pb push_back
#define sc scanf
#define pr printf
#define f first
#define s second
#define mp make_pair
#define lb lower_bound

using namespace std;

int w[20];

int main (){
    int n,m,a,b,t;
    char c;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%d%d",&n,&m);
        int *ta;
        int il=0;
        ta=new int[n+1];
        bool *bi;
        bi=new bool[n+1];
        for(int j=0;j<=n;j++){
            ta[j]=0;
            bi[j]=0;
        }
        for(int j=0;j<m;j++){
            sc("%d %c%d",&a,&c,&b);
            if(c=='>'){
                ta[b]++;
                if(ta[b]==n)w[i]=1;
            }
            else{
                if(bi[b]==0){
                    il++;
                    bi[b]=1;
                    if(il==n)w[i]=-1;
                }
            }
        }
        delete[]ta;
        delete[]bi;
    }
    for(int i=0;i<t;i++){
        if(w[i]==1)pr("WYGRANA\n");
        else if(w[i]==0)pr("REMIS\n");
        else pr("PRZEGRANA\n");
    }
    return 0;
}