A Smart Brain is a Tasty Brain

Time limit1sMemory limit128 MB

Problem

The zombies have cornered you and your team. There's no hope... but then they stop and, instead of eating you, offer a deal. As it turns out, zombies have trouble finding good-tasting brains — and to a zombie, a good-tasting brain is a smart brain. Your brains would be delicious, but the zombies decide they are better used to help find other smart brains. The deal: help them decide whether a given brain is smart (and therefore tasty), and they will let your team go — at least for now.

A brain is judged smart if it can correctly evaluate a given Boolean expression. You compile a list of Boolean expressions and test each brain on one of them; the brain reports the value it computed.

Every Boolean expression is deterministic and is defined recursively:

  1. expression = '(' + (value or expression) + operation + (value or expression) + ')'
  2. value = 't' or 'f'
  3. operation = '&' or '|'
  4. Any value or expression may be preceded by an optional !.

The expression contains no characters other than those below:

  1. & is AND: (a&b) is true only when both a and b are true; otherwise false.
  2. | is OR: (a|b) is false only when both a and b are false; otherwise true.
  3. ! is NOT: it flips the value immediately following it.
  4. ( and ) bound an expression; everything inside the parentheses is evaluated first, and every ( has a matching ).
  5. t and f represent true and false, respectively.

Input

The first line contains an integer $x$ with $0 < x \le 10000$. Each of the next $x$ lines contains one complete Boolean expression (at most 50 characters), followed by a space, an equals sign =, another space, and the tested brain's evaluation of that expression (either t or f).

Output

For each tested brain, on its own line, print the brain's number, then a colon and a space, then Good brain if the expression was evaluated correctly or Bad brain if it was not. Once you are finished, you might want to start running as fast as you can — the zombies will only give you so much of a head start.