Universal Question Answering System#3090

Universal Question Answering System

2 seconds
64 megabytes
Hard

Every student needs help in gaining new knowledge by asking questions. Surveys show that some similar questions are frequently repeated. Therefore, it would be useful to develop an automatic question-answering system to answer such questions. Your algorithm should have no prior knowledge, but it must be able to read sentences and remember the mentioned facts. Whenever a question about such a fact is asked, the system must answer it correctly.

Input

The input consists of several dialogues.

The first line contains a single positive integer (T \leq 500, but note that of them are relatively small). It denotes the number of dialogues. Each dialogue consists of one or more lines. Each line contains a sentence: either a statement or a question. Statements end with a dot (), while questions end with a question mark (). After each dialogue, there is an extra line that ends with an exclamation mark (). The definitions of statements and questions will be discussed later.

Sentences can contain words, spaces, and punctuation marks. All words consist only of Latin letters and are case-sensitive. Unlike the normal rules of English writing, the first letter of a sentence should remain lowercase unless the first word itself must begin with a capital letter. There are no extra spaces between words. No word will have more than characters. There will be at most lines in any dialogue.

Statements

Each statement has one of the following forms:

noun_phrase are noun_phrase. noun_phrase can verb_phrase. everything which can verb_phrase can verb_phrase. everything which can verb_phrase are noun_phrase.

Here, noun_phrase and verb_phrase are both single words. The meanings of the four forms are:

are : If is , then is .

can : If is , then can .

everything which can can : If can , then can .

everything which can are : If can , then is .

Questions

Each question has one of the following forms:

are noun_phrase noun_phrase? can noun_phrase verb_phrase? can everything which can verb_phrase verb_phrase? are everything which can verb_phrase noun_phrase?

These are the question forms of the statements.

In each test case, the number of different noun phrases will not exceed , and the number of different verb phrases will not exceed .

Output

For each test case, output two lines. The first line describes the test case number, starting from , and the second line contains as many characters as the number of questions in this test case. Each character is either Y (meaning you can logically obtain that fact) or M (otherwise), without quotes.

Examples

Example 1

Loading
Loading