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.
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.
The first line has the number of test cases N (1≤N≤100). Each of the next N 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.00 and 999999999999999.99. The amount in words is lowercase words joined by single spaces, and it is at most 500 characters long.
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.