Papa

No attempts yetTime limit1sMemory limit128 MB

Problem

While cleaning your parents' attic, you found a box of documents that describe the relationships among your ancestors. Using these documents, you want to answer a number of questions about the relationships they imply. Fortunately, every ancestor has a unique name, so many facts can be inferred without confusion.

Every relationship (given or inferred) satisfies the following rules:

  • A person is male, female, or of unknown (undetermined) sex.
  • A person has at most one spouse, of the opposite sex; X is Y's wife if and only if Y is X's husband.
  • A person has at most one mother and at most one father that can be inferred from the data.
  • If a person has both a mother and a father, then that mother and father are married.
  • The children of a person's spouse are also that person's children.
  • The spouse of a son (or daughter) is not treated as a daughter (or son); "son" and "daughter" always mean a biological son or daughter.

The information is always consistent, and you may assume there are no relationships other than those explicitly stated or implied by the rules above.

Input

The first part of the input is a list of known relationships, one per line, in the form:

NAME is NAME's RELATIONSHIP.

Here NAME is a lowercase alphabetic word (never the word is), and RELATIONSHIP is one of:

  • wife
  • husband
  • daughter
  • son
  • mother
  • father

This part ends with a blank line. There is at least one known relationship, and at most 100 distinct names appear among the known relationships.

Next comes a list of questions, one per line, in the form:

is NAME NAME's RELATIONSHIP?

where NAME is as above and RELATIONSHIP is one of:

  • wife
  • husband
  • daughter
  • son
  • mother
  • father
  • niece: X is a niece of Y if there exist W and Z such that X is a daughter of W, and W and Y are two distinct children of Z.
  • nephew: X is a nephew of Y if there exist W and Z such that X is a son of W, and W and Y are two distinct children of Z.
  • grandfather: X is a grandfather of Y if there is a Z such that X is the father of Z, and Z is the father or mother of Y.
  • grandmother: X is a grandmother of Y if there is a Z such that X is the mother of Z, and Z is the father or mother of Y.
  • grandson: X is a grandson of Y if there is a Z such that X is the son of Z, and Z is a child of Y.
  • granddaughter: X is a granddaughter of Y if there is a Z such that X is the daughter of Z, and Z is a child of Y.

Every name used in the questions also appears in the known relationships. The list of questions ends at end of file.

Output

For each question, print a single line containing yes or no if the answer can be determined, or unknown if the answer could be either yes or no because the sex of the relevant person(s) cannot be determined from the known relationships.