跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1742. A and B and Lecture Rooms

    ID: 1748 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>二分数据结构搜索动态规划算法思想提高难度共享题库Codeforces英文题面题目来源题面语言

A and B and Lecture Rooms

题目描述

E. A and B and Lecture Rooms
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A and B are preparing themselves for programming contests.

The University where A and B study is a set of rooms connected by corridors. Overall, the University has n rooms connected by n-1 corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from 1 to n.

Every day A and B write contests in some rooms of their university, and after each contest they gather together in the same room and discuss problems. A and B want the distance from the rooms where problems are discussed to the rooms where contests are written to be equal. The distance between two rooms is the number of edges on the shortest path between them.

As they write contests in new rooms every day, they asked you to help them find the number of possible rooms to discuss problems for each of the following m days.

Input

The first line contains integer n (1≤n≤105) − the number of rooms in the University.

The next n-1 lines describe the corridors. The i-th of these lines (1≤in-1) contains two integers ai and bi (1≤ai,bin), showing that the i-th corridor connects rooms ai and bi.

The next line contains integer m (1≤m≤105) − the number of queries.

Next m lines describe the queries. The j-th of these lines (1≤jm) contains two integers xj and yj (1≤xj,yjn) that means that on the j-th day A will write the contest in the room xj, B will write in the room yj.

Output

In the i-th (1≤im) line print the number of rooms that are equidistant from the rooms where A and B write contest on the i-th day.

Examples
Input
4
1 2
1 3
2 4
1
2 3
Output
1
Input
4
1 2
2 3
2 4
2
1 2
1 3
Output
0
2
Note

in the first sample there is only one room at the same distance from rooms number 2 and 3 − room number 1.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1290 题。保留原作者与原赛事署名。