Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Big Problems for Organizers

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThe Finals of the "Russian Code Cup" 2214 will be held in *n* hotels. Two hotels (let's assume that they are the main hotels), will host all sorts of events, and the remaining hotels will accommodate the participants. The hotels are connected by *n* - 1 roads, you can get from any hotel to any other one.

The organizers wonder what is the minimum time all the participants need to get to the main hotels, if each participant goes to the main hotel that is nearest to him and moving between two hotels connected by a road takes one unit of time.

The hosts consider various options for the location of the main hotels. For each option help the organizers to find minimal time.

Input

The first line contains an integer *n* (2 ≤ *n* ≤ 100000) — the number of hotels. The next *n* - 1 lines contain two integers each — the numbers of the hotels that have a road between them. Consider hotels are numbered from 1 to *n*.

The next line contains an integer *m* (1 ≤ *m* ≤ 100000) — the number of queries. The following *m* lines contains two distinct integers each — the numbers of the hotels we assume to be the main.

Output

For each request of the organizers print a single integer — the time that all participants need to reach the main hotels.

Examples

Input

3

2 3

3 1

3

2 1

2 3

3 1

Output

1

1

1

Input

4

1 4

1 2

2 3

3

1 4

1 3

2 3

Output

2

1

2

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/19/2018 07:28:09 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|