Error Correction

No attempts yetTime limit1sMemory limit128 MB

Problem

Alice and Bob, regular characters in cryptography textbooks, have agreed on an encryption algorithm, exchanged keys, and are now thinking about how to send encrypted messages (from here on, messages) over the channel available to them. A message is a sequence of lowercase English letters. They decided to use a binary code and assigned each letter some bit string. They did not require these strings to all have the same length, nor that no string be a prefix of another. Because of this, an encoded message cannot always be decoded uniquely. It is guaranteed, however, that the bit strings assigned to different letters are all distinct. The bit string of an encoded message is formed by concatenating, in order, the bit strings of that message's successive letters.

Your task is to write a decoding program for Alice and Bob. We say that a message MM corresponds to a bit string BB if BB and the encoding of MM have the same length and differ in at most one bit (that is, they differ in at most one position). If exactly one message corresponds to a given bit string, your program should print it. If no message corresponds, or more than one does, the program should report that.

Write a program that:

  • reads from standard input the bit strings assigned to the letters and the bit strings to be decoded,
  • for each bit string decides whether it can be decoded uniquely and, if so, decodes it,
  • prints the results to standard output.

Input

The first line contains an integer nn (1n261 \le n \le 26), the number of letters used. Each of the next nn lines contains one lowercase English letter, a single space, and the bit string assigned to that letter (digits 0 and 1 only, with no spaces between them). Each letter appears at most once. The total length of the bit strings does not exceed 150.

The next line contains an integer mm (1m101 \le m \le 10), the number of messages to decode. Each of the next mm lines contains one message: a sequence of the digits 0 and 1, with no separating spaces, of length at most 10000.

Output

Print the decoding result for each message, in the order given in the input.

  • If no message corresponds to a given bit string, print BLAD on a single line.
  • If more than one message corresponds, print ZBYT WIELE on a single line.
  • If exactly one message corresponds, print OK on one line and the decoded message on the next line.