
| Contests | Virtual Contests | Problems | Submit | Runs Status | Rank List | Forum |
Tree is one of the most common structures in computer programming. Now given a tree structure, your task is to determine whether a node is an ancestor of another one or not.
Input
The first line of the input is one integer T which is the number of test cases. Each test case starts with an integer N (1 ≤ N ≤ 10000) , the number of the node in the given tree. The nodes' number starts from 0 (see in the figure). Then the following (N-1) pairs of integer s and t describe the tree — the node t is the father of the node s. The next integer M (1 ≤ M ≤ 100000) is the number of the queries followed by M pairs of a and b for the querying.
It is promised that the node 0 is always the root of the given tree.
Output
For each query, you have to determine whether the node a is an ancestor of the node b. If so, print "Yes", otherwise print "No". You are required to output a blank line after each case.
Sample Input
1
6
1 0
2 0
3 1
4 2
5 3
5
0 1
0 5
1 4
2 4
2 2
Sample Output
Yes
Yes
No
Yes
No
Note: Any node is not the ancestor of itself.