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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;

#define pi pair<int,int>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define pl pair<long long,long long>
#define pb push_back

int los[100005],win[100005];

int main()
{
    int n,m,z,a,b;
    char x;

    scanf ("%d", &z);

    while (z--)
    {
        scanf ("%d%d", &n, &m);

        for (a=1; a<=n; a++)
            los[a]=win[a]=0;

        while (m--)
        {
            scanf ("%d %c %d", &a, &x, &b);

            if (x=='<')
                win[b]++;
            else
                los[b]++;
        }

        for (a=1; a<=n && los[a]!=n; a++);

        if (a<=n)
            printf ("WYGRANA\n");
        else
        {
            for (a=1; a<=n && win[a]; a++);

            if (a>n)
                printf ("PRZEGRANA\n");
            else
                printf ("REMIS\n");
        }
    }

    return 0;
}