Distance on Triangulation
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

You have a convex polygon. The vertices of the polygon are successively numbered from 1 to n. You also have a triangulation of this polygon, given as a list of n − 3 diagonals.
You are also given q queries. Each query consists of two vertex indices. For each query, find the shortest distance between these two vertices, provided that you can move by the sides and by the given diagonals of the polygon, and the distance is measured as the total number of sides and diagonals you have traversed.

输入描述:

The first line of the input file contains an integer n — the number of vertices of the polygon (4 ≤ n ≤ 50 000).
Each of the following n−3 lines contains two integers ai, bi — the ends of the i-th diagonal (1 ≤ ai, bi ≤ n, ai ≠ bi).
The next line contains an integer q — the number of queries (1 ≤ q ≤ 100 000).
Each of the following q lines contains two integers xi, yi — the vertices in the i-th query (1 ≤ xi, yi ≤ n).
It is guaranteed that no diagonal coincides with a side of the polygon, and that no two diagonals coincide or intersect.

输出描述:

For each query output a line containing the shortest distance.
示例1

输入

复制
6
1 5
2 4
5 2
5
1 3
2 5
3 4
6 3
6 6

输出

复制
2
1
1
3
0

说明