Tom and Jerry like to draw trees. One day Tom drew a tree, and soon he found another tree drawn by Jerry. He thinks that Jerry has copied his tree and added some nodes and edges, and for safety he may have changed the label of the nodes (but not the root). So, Tom asks your help.
A tree is a connected graph with no cycles. They both drew rooted trees, now your task is to find whether Jerry has modified Tom's tree or not.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a line containing an integer n (2 ≤ n ≤ 100) denoting the number of nodes in Jerry's tree. Each of the next n-1 lines contains two integers ui vi (1 ≤ ui, vi ≤ n, ui ≠ vi) denoting that there is an edge between ui and vi in Jerry's tree.
The next line contains an integer m (1 ≤ m < n) denoting the number of nodes in Tom's tree. Each of the next m-1 lines contains two integers pi qi (1 ≤ pi, qi ≤ m, pi ≠ qi) denoting that there is an edge between pi and qi in Tom's tree.
For both trees, 1 is the root.
Output
For each case, print the case number and Yes
if Jerry has modified Tom's tree or No
otherwise.
Sample
Sample Input | Sample Output |
---|---|
2 4 1 2 2 4 1 3 3 1 3 3 2 5 1 2 2 4 1 3 3 5 4 1 3 1 2 1 4 | Case 1: Yes Case 2: No |