There is a tree with $n$ nodes where A and B are playing hide-and-seek, with A chasing B.
Initially, the two players are at different nodes. The game proceeds in several rounds. In each round:
- B obtains the current distance from A to B. B can obtain this distance once per round, but B does not know A's exact location.
- Both players move simultaneously:
- A always moves one step closer to B.
- B can choose to move to any adjacent node or stay at the current node.
- The game ends if both players are at the same node or if they cross the same edge.
B wants to maximize the number of rounds the game lasts. If the game ends by crossing the same edge in the final round, that round is considered to have lasted only half a round.
There are several game scenarios. For the $i$-th scenario, you are given B's initial position $v_i$ and the initial distance $d_i$ from A to B. You need to find the number of rounds B can make the game last in the worst-case scenario.
The worst-case scenario means that A can always be at any node that is consistent with the distances obtained in all previous rounds, so a random strategy is ineffective. In other words, the "interactor is adaptive." You can better understand this through the example explanations.
Input
The first line contains two positive integers $n$ and $Q$, representing the number of nodes and the number of game scenarios.
The next $n-1$ lines each contain two positive integers $u_j, v_j$, representing an edge.
The next $Q$ lines each contain two positive integers $v_i, d_i$, representing a game scenario.
Output
Output $Q$ lines, each containing a positive integer representing the answer for the $i$-th game scenario. It can be proven that the answer is always a positive integer.
Examples
Input 1
5 2 1 2 2 3 3 4 4 5 1 4 3 1
Output 1
4 1
Note 1
For the first game scenario, one can deduce that A is at node 5 based on the distance, so B's optimal strategy is to stay put.
For the second game scenario, A could be at node 2 or node 4. However, regardless of where B moves, the worst-case scenario is that B is caught after half a round. Therefore, the optimal strategy is still to stay put.
Input 2
11 2 1 2 2 3 1 4 4 5 1 6 6 7 7 8 1 9 9 10 10 11 3 2 10 4
Output 2
2 5
Constraints
For all data, it is guaranteed that $2 \le n \le 10^5$, $1 \le Q \le 10^5$, $1 \le v_j \le n$, $1 \le d_j \le n-1$.