2014
02-12

# Firebirds’ Logic Nation

In HDU, there is an little world created by GL, WYB, and CTW. This world lives some birds which are recognized as firebirds. Actually, the firebirds’ world exists three kind of birds, respectively created by GL, WYB, CTW. So I will call them "Gbird", "Wbird", "Cbird" below.
What’s more, these birds can talk to ACMers and have their own habit as follows:
Gbird are like GL, never tell truth. Wbird like to tell the truth in the day, but lie in the night. While Cbird are all honest, and never lie.
Now, some firebirds talk to you and tell you some statements, can you deduce what kind of these birds are, and whether it’s day or night?

The input contains several cases. Each description starts with two integer n and m respectively represent the number of birds and statements. Then following m lines each contain one statement. And one statement is begin with "X: ", X is the identity of speaker. Then follows the contents, like following kinds:

I am [not] ( Gbird | Wbird | Cbird | lying ).
X is [not] ( Gbird | Wbird | Cbird | lying ).
It is ( day | night ).

The word in [] may appear or not appear. The word in () mean that exactly one of the words separated by | must appear. X is the identity of birds, it’s a uppecase character between ‘A’ and ‘Z’.
0 < n < 27, 0 < m < 100, ‘A’ <= X <= ‘Z’.
Input end with a case n = 0 and m = 0.

The input contains several cases. Each description starts with two integer n and m respectively represent the number of birds and statements. Then following m lines each contain one statement. And one statement is begin with "X: ", X is the identity of speaker. Then follows the contents, like following kinds:

I am [not] ( Gbird | Wbird | Cbird | lying ).
X is [not] ( Gbird | Wbird | Cbird | lying ).
It is ( day | night ).

The word in [] may appear or not appear. The word in () mean that exactly one of the words separated by | must appear. X is the identity of birds, it’s a uppecase character between ‘A’ and ‘Z’.
0 < n < 27, 0 < m < 100, ‘A’ <= X <= ‘Z’.
Input end with a case n = 0 and m = 0.

1 1
A: I am Cbird.
1 1
A: I am lying.
3 4
A: B is Wbird.
B: C is Wbird.
C: A is Wbird.
C: I am Gbird.
0 0

Case #1:
I messed up.
Case #2:
You're kidding.
Case #3:
A is a Gbird.
B is a Cbird.
C is a Wbird.
It is night.

Hint
hints： case 1: You cannot reduce anything from it. case 2: If A is lying, then it's telling a truth. If it's telling a truth, it's lying. So it cannot happen according to the rules. case 3: Gbird won't say itself is a Gbird, so C is lying(statement 4 is false). You can reduce that it is night and C is a Wbird. So B is telling the truth(statement 2 is true). It's a Cbird. A is not a Wbird(statement 3 is false) and is not a Cbird(statement 1 is false). So A is a Wbird.