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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <cstdlib>
using namespace std;

class pack {
    public:
        int firstCompetitor;
        int secondCompetitor;
        int whoWin;

    void setFirstCompetitor(int data) {
        firstCompetitor = data;
    }
    void setSecondCompetitor(int data) {
        secondCompetitor = data;
    }
    void setWhoWin(int data) {
        whoWin = data;
    }

    int getFirstCompetitor() {
        return firstCompetitor;
    }
    int getSecondCompetitor() {
        return secondCompetitor;
    }
    int getWhoWin() {
        return whoWin;
    }

};

pack game[200000]; //array contains data Input
bool availablePackFirst[100000];//array to marks used pack
bool availablePackSecond[100000];

void clearTablePackFirst(int numberPack) {
    for(int i = 0; i < numberPack; ++i) {
        availablePackFirst[i] = false;
    }
}

void clearTablePackSecond(int numberPack) {
    for(int i = 0; i < numberPack; ++i) {
        availablePackSecond[i] = false;
    }
}

void setInputData(int numberWinOrLose) {
    int firstPack;
    int secondPack;
    char result;

    for(int i = 0; i < numberWinOrLose; ++i) {
        cin >> firstPack >> result >> secondPack;

        game[i].setFirstCompetitor(firstPack);
        game[i].setSecondCompetitor(secondPack);

        if(result == '>') {
            game[i].setWhoWin(1);
        }
        else {
            game[i].setWhoWin(2);
        }
    }
}


int main(int argc, char *argv[])
{
    ios_base::sync_with_stdio(false);
    int numberPack;
    int numberWinOrLose;
    int winnerFirstCompetitor = 0;
    int winnerSecondCompetitor = 0;

    int t;
    cin >> t;
    while(t--) {
        cin >> numberPack >> numberWinOrLose;
        setInputData(numberWinOrLose);
        clearTablePackFirst(numberPack);
        clearTablePackSecond(numberPack);

        for(int i = 0; i < numberWinOrLose; ++i) {
            if(game[i].getWhoWin() == 1 && availablePackFirst[game[i].getFirstCompetitor()] == false) {
                winnerFirstCompetitor++;
                availablePackFirst[game[i].getFirstCompetitor()] = true;
            }
            if(game[i].getWhoWin() == 2 && availablePackSecond[game[i].getSecondCompetitor()] == false) {
                winnerSecondCompetitor++;
                availablePackSecond[game[i].getSecondCompetitor()] = true;
            }
        }

        if(winnerFirstCompetitor < numberPack && winnerSecondCompetitor == numberPack) {
            cout << "PRZEGRANA" << endl;
        }
        if(winnerFirstCompetitor == numberPack && winnerSecondCompetitor < numberPack) {
            cout << "WYGRANA" << endl;
        }
        if(winnerFirstCompetitor < numberPack && winnerSecondCompetitor < numberPack) {
            cout << "REMIS" << endl;
        }
        if(winnerSecondCompetitor == numberPack && winnerFirstCompetitor == numberPack) {
            int randomNumber = rand()%2;
            if(randomNumber == 1) {
                cout << "PRZEGRANA" << endl;
            }
            else {
                cout << "REMIS" << endl;
            }
        }

        winnerFirstCompetitor = 0;
        winnerSecondCompetitor = 0;

    }
    return 0;
}