#P1606F. Tree Queries
Tree Queries
Description
You are given a tree consisting of vertices. Recall that a tree is an undirected connected acyclic graph. The given tree is rooted at the vertex .
You have to process queries. In each query, you are given a vertex of the tree and an integer .
To process a query, you may delete any vertices from the tree in any order, except for the root and the vertex . When a vertex is deleted, its children become the children of its parent. You have to process a query in such a way that maximizes the value of (where is the resulting number of children of the vertex , and is the number of vertices you have deleted). Print the maximum possible value you can obtain.
The queries are independent: the changes you make to the tree while processing a query don't affect the tree in other queries.
The first line contains one integer () — the number of vertices in the tree.
Then lines follow, the -th of them contains two integers and (; ) — the endpoints of the -th edge. These edges form a tree.
The next line contains one integer () — the number of queries.
Then lines follow, the -th of them contains two integers and (; ) — the parameters of the -th query.
For each query, print one integer — the maximum value of you can achieve.
Input
The first line contains one integer () — the number of vertices in the tree.
Then lines follow, the -th of them contains two integers and (; ) — the endpoints of the -th edge. These edges form a tree.
The next line contains one integer () — the number of queries.
Then lines follow, the -th of them contains two integers and (; ) — the parameters of the -th query.
Output
For each query, print one integer — the maximum value of you can achieve.
Note
The tree in the first example is shown in the following picture:

Answers to the queries are obtained as follows:
- : you can delete vertices and , so the vertex has children (vertices , , , , and ), and the score is ;
- : you can delete the vertex , so the vertex has children (vertices , , , and ), and the score is .
- : you shouldn't delete any vertices, so the vertex has only one child (vertex ), and the score is ;
- : you can delete the vertex , so the vertex has children (vertices , , , , and ), and the score is ;
- : no matter what you do, the vertex will have no children, so the score is ;
- : you shouldn't delete any vertices, so the vertex has children (vertices , , , and ), and the score is .