The city of Kyoto is famous for its grid plan: every street runs either north-south or east-west. Some streets are numbered, but most have proper names.
A crossing is named after the two streets that meet there; for example, Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo street. But there is a problem: which name should come first? At first the order seems arbitrary: one crossing is called Kawaramachi-Sanjo (north-south first), yet another is called Shijo-Kawaramachi (east-west first). With some experience one realizes that there is actually an "order" (a strength) on the streets. In the example above, Shijo is "stronger" than Kawaramachi, which in turn is "stronger" than Sanjo. This order can be used to deduce the names of other crossings.
You are given a list of known crossing names X-Y. Each street runs either north-south or east-west, and only orthogonal streets may cross.
Because the list is very incomplete, you first complete it using the following rule.
Two streets A and B have equal strength if all of (1)-(3) hold:
Using this definition, extend the strength relation.
A is stronger than B when there is a sequence $A = A_1, A_2, \ldots, A_n = B$ with $n \ge 2$, where for every $i,(1 \le i \le n-1)$, either $A_i\text{-}A_{i+1}$ is an input crossing or $A_i$ and $A_{i+1}$ have equal strength.
Then you are asked whether other possible crossing names X-Y are valid. Answer affirmatively if you can infer that a name is valid, and negatively otherwise. Concretely:
The input is a sequence of data sets, each of the form
N
Crossing1
...
CrossingN
M
Question1
...
QuestionM
Both Crossings and Questions have the form
X-Y
where X and Y are strings of alphanumeric characters of length at most 16. There is no whitespace, and alphabetic characters are case-sensitive.
$N$ and $M$ are each between 1 and 1000 inclusive, and there are no more than 200 streets in a data set.
The last data set is followed by a line containing a single zero.
For each data set, output $M+1$ lines. The first line contains the number of distinct streets appearing in the Crossing part of the input, followed by the answer to each question, one per line, either YES or NO with no spaces.