Check Amount Validation

No attempts yetTime limit1sMemory limit256 MB

Problem

A check carries its amount twice, once in words and once in digits. If the two disagree, the check is invalid. Comparing them by eye is slow, so a bank scans its checks, reads the English words with character recognition, and needs a program that compares the words with the digits.

An amount in words is built from exactly these words:

one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand, million, billion, trillion, rupees, paisas, and, only

If any other word appears, the string is not well formatted.

The words must follow this grammar.

  • A small part is a number from 1 to 99. It is one word from one to nineteen, or one tens word (twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety), or a tens word followed by one word from one to nine.
  • A group is a number from 1 to 999. It is a small part, or a word from one to nine followed by hundred, optionally followed by a small part.
  • The rupee amount is a group followed by trillion, then a group followed by billion, then a group followed by million, then a group followed by thousand, then a final group with no scale word, written in exactly that order. Each of these five pieces may be left out, but at least one must remain, so a scale word never appears twice and the scale words never appear out of order.
  • The word rupees comes after the rupee amount.
  • If the fractional part is not zero, the words and, a small part, and paisas follow, in that order. If the fractional part is zero, none of the three appears.
  • The string ends with only, and nothing follows only.

One rupee is 100 paisas. Every group is between 1 and 999, so a group worth zero is never written out. The word hundred is used whenever it applies, so 999 is nine hundred ninety nine and never nine ninety nine. The word thousand is used whenever it applies, so 7535 is seven thousand five hundred thirty five and never seventy five hundred thirty five. The largest amount is nine hundred ninety nine trillion nine hundred ninety nine billion nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine rupees and ninety nine paisas only, and the smallest is one rupees only.

Input

The first line has the number of test cases NN (1N1001 \le N \le 100). Each of the next NN lines has the amount in digits, one space, then the amount in words. The amount in digits has exactly two decimal places and lies between 1.001.00 and 999999999999999.99999999999999999.99. The amount in words is lowercase words joined by single spaces, and it is at most 500 characters long.

Output

For each test case print one line of the form Case #n: r, where n is the test case number counting from 1. Print Bad when the words are not well formatted, Match when the words are well formatted and mean the same amount as the digits, and No Match when the words are well formatted but mean a different amount.