10328 - Lab10   

Description

Suppose we have 100 variables (variable 1 ~ variable 100) and a series of equivalence relations.
For instance, 2 3 represents that variable 2 and 3 are equivalent.
Given a query, your job is to count how many variables equal to the queried variable (except for the queried variable)

Input

M (the count of equivalence relations)
Relation 1
Relation 2

Relation M
P (the count of queries)
Query 1
Query 2

Query P

Output

For each query, output how many variables equal to the queried variable.
Print a newline '\n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss