Every customer occasionally needs help with new or unfamiliar products, so a hotline service matters to any company. Ideally there is a single phone number where a customer can always reach a friendly voice ready to help with anything. Staffing such a hotline, however, needs many operators, and labor is expensive. It is also hard to keep a friendly voice at 4am while explaining to a drunk caller that you really cannot give them the phone number of the House of Parliament. On top of that, many questions repeat, and answering them over and over is tedious.
A modern company wants to solve its hotline problem by building software that can answer the most common questions automatically. The caller's voice is analysed by a Voice Recognition Module (VRM) and converted to plain text. That text is then processed by an Artificial Automatic Adaptive Answering Algorithm (AAAAA). Common questions are recognised and answered automatically, and the replies are converted back to sound by a Text-to-Speech Module (TTS).
Your task is to implement the AAAAA module. Because it must be adaptive, it has no built-in knowledge base. Instead it listens to sentences in English, remembers the facts stated, and when a question is asked about such a fact it must answer correctly. The VRM and TTS modules already exist, so the input and output of the AAAAA module are both plain text.
The first line of input contains a single positive integer T, the number of dialogues that follow. Each dialogue consists of zero or more lines, each holding one sentence that is either a statement or a question. A statement ends with a period (.), a question ends with a question mark (?). No statement appears more than once, but questions may repeat. Each dialogue is followed by one extra line ending with an exclamation mark (!).
Sentences may contain words, spaces and punctuation (commas, colons, semicolons, etc.). All words use only letters of the English alphabet and are case-sensitive, so the same word is always spelled the same way, usually in lowercase. Acronyms, names and a few other words may begin with a capital letter. For simplicity every sentence begins with a lowercase letter, except that the first word is capitalized only when it must be. There are no unnecessary spaces between words, no line exceeds 100 characters, and there are at most 100 statements per test case.
Each statement has one of the following two forms:
subject predicate[s][ object].
subject don't|doesn't predicate[ object].
The square brackets mark an optional part and the vertical bar two alternatives. The subject is a single word: a noun or a singular pronoun. The predicate is a single-word verb describing an activity. The object may be any text and never contains a period. Each pair "verb + object" defines a unique activity: the same verb with different objects means different, independent activities. A sentence without an object is treated as one with an empty object, and a verb without an object has a different, independent meaning from the same verb with a non-empty object.
The first form is a positive statement. In "predicate[s]" the verb agrees with the subject: if the subject is "I" or "you" the verb is the infinitive; with any other subject an "s" is appended. Assume there are no irregular verbs.
The second form is a negative statement. The auxiliary "don't" or "doesn't" must also agree with the subject: "don't" is used with "I" or "you", "doesn't" otherwise.
There is a special generic subject "everybody", meaning the activity holds for every subject, and another generic subject "nobody", which also applies to every subject but with a negative meaning. Both generic subjects are used only with the first form (never with "doesn't"). The sentence "nobody likes something" is exactly equivalent to "everybody doesn't like something", except that the latter form never appears in the input.
For each dialogue, output the line Dialogue #D:, where D is the dialogue's sequence number starting from 1. Then, for every question, print exactly three lines: the first repeats the question, the second is the answer, and the third is empty. Print nothing for statements. After the dialogue, print the same line ending with an exclamation mark that appeared in the input, followed by one extra empty line. An empty line contains only a newline character.
The answer must be formatted so a TTS module can read it. Only the statements that appear before the question are used to build its reply. If the known statements contradict each other, the reply is always I am abroad.. If a question or statement uses the special subject "you", it becomes "I" in the answer; if it uses the special subject "I", it becomes "you" in the answer. The verb must always agree with the subject of the sentence. The exact form of the answer depends on the type of question.
If there is a positive statement about that subject (or the generic subject "everybody") with the given predicate and object, the answer is:
yes, subject predicate[s][ object].
If there is a negative statement about that subject (or the generic subject "nobody") with the given predicate and object, the answer is:
no, subject don't|doesn't predicate[ object].
Otherwise the answer is: maybe.
The subject in the answer is always the same subject as in the question.
If there is a positive statement with any subject, the given predicate and object, the answer is:
subject predicate[s][ object].
If two or more subjects match the activity, replace the subject in the answer with all of them, in the order the corresponding statements appeared. Subjects are separated by a comma and a space, and the last two are separated by the word "and". If "everybody" is among the matching subjects, do not list the others and print only "everybody". If the list contains at least two subjects the verb takes the plural form (no trailing "s"); otherwise it agrees with the single subject.
subject1, subject2 and subject3 predicate[ object].
If there is a negative statement with the generic subject "nobody", the given predicate and object, the answer is:
nobody predicates[ object].
Otherwise the answer is: I don't know.
If there are one or more statements (positive or negative) about that subject (or a generic subject "everybody" or "nobody"), every verb and object from those statements must appear in the reply, in the order the corresponding statements appeared. No verb-object pair may appear more than once (skip any later repeat). Verb-object pairs are separated by a comma and a space, and the last verb is preceded by a comma and the word "and". Note the comma here, unlike when separating subjects above. Negative items keep the statement form, using "don't" or "doesn't":
subject[ don't|doesn't] predicate1[s][ object1],
[ don't|doesn't] predicate2[s][ object2],
and[ don't|doesn't] predicate3[s][ object3].
subject[ don't|doesn't] predicate1[s][ object1],
and[ don't|doesn't] predicate2[s][ object2].
subject[ don't|doesn't] predicate[s][ object].
Otherwise the answer is: I don't know.