3051: Go For Travel

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:1 通过:1

题目描述

There are $n$ cities in the $Rainbow Island$, connected by $n-1$ bidirectional roads.

$Lizishu$ is fond of travel. In the $i_{th}$ of each $m$ years, she would go for travel from city $x_{i}$ with $k_{i} \ Yuan$ and she would cost $1 \ Yuan$ leaving a city to an adjacent one. For seeing more scenery, she wants to go to as many different cities as possible.

Now you are given the map of the $Rainbow Island$ and you should tell $Lizishu$ the maximum number of different cities (including $x_{i}$) she can reach every year.

Note that every time she can only go to an adjacent city and cost $1 \ Yuan$.

输入格式

The first line contains an integer number $T$, the number of test cases.

For each test case :
The first line contains an integer $n(1 \leq n \leq 10^{5})$, the number of vertices.

The following $n-1$ lines, each contains two integers $u, v (1 \leq u, v \leq n)$,  which means there is an edge between $u$ and $v$.

It is guaranteed that the graph is connected.

The next line contains an integer $m(1 \leq m \leq 10^{6})$, the number of years.

The following $m$ lines, the $i_{th}$ line contains two integers $x_{i} (1 \leq x_{i} \leq n), k_{i}(1 \leq k_{i} \leq 10^{6})$, the index of the city she starts travel and the money she carries in the $i_{th}$ year.

输出格式

For each year print the answer.

输入样例 复制

1
6
1 2
1 3
2 4
2 5
3 6
2
2 2
2 4

输出样例 复制

3
4