Hooligan

No attempts yetTime limit1sMemory limit128 MB

Problem

Soccer is the American English word for the sport that British English calls football — the most popular sport in Latin America (and in the world). Hooligan is sometimes used to describe an aggressive, troublemaking soccer fan.

In Linearonia, a soccer tournament is under way. Ranking works as follows: for each game the winner earns $2$ points and the loser earns $0$ points; in case of a tie, each team earns $1$ point. The champion is the team with the most points. Every pair of distinct teams plays against each other exactly the same number of times, called the matching number $M$.

You support one team — your dream team, numbered $0$ — and you wonder whether it can still become the champion. You are given the number of teams, the matching number, and the results of some games already played. Decide whether, after all remaining games are played, your dream team can end up as the sole champion, with strictly more points than every other team.

Input

The input contains several test cases. Each test case consists of one or more lines. The first line has three integers $N$, $M$ and $G$ separated by single spaces: the number of teams ($2 \le N \le 40$), the matching number ($1 \le M \le 4$), and the number of games already played ($1 \le G$). Your dream team is team $0$; the other teams are numbered $1, 2, \ldots, N-1$.

Each of the next $G$ lines describes one game already played. The line contains an integer $I$, a character $C$ and an integer $J$ separated by single spaces ($I \ne J$ and $0 \le I, J \le N-1$). The character $C$ is < if team $I$ lost to team $J$, or = if the game was a tie.

The last test case is followed by a line containing three zeros (0 0 0) separated by single spaces, which must not be processed.

Output

For each test case, print a single line with one character: uppercase Y if your dream team can be the sole champion, or uppercase N otherwise.