City Development
Time limit3sMemory limit512 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
The city of Baytsburg has a historical part and a new part. The historical part is a tree of squares connected by avenues. The squares are numbered consecutively from 1 to . The main square of the city, vertex 1, is the root of the tree.
At the start, the city consists only of the historical part. Each year the city develops as follows. Let be the number of squares at the start of the year.
- Choose a square in the historical part and a square among those already built (in the historical part or in the new part).
- The subtree of the historical part rooted at is copied entirely into the new part, then the root of the copied subtree is connected by an avenue to square . All built objects (squares and avenues) belong to the new part. The historical part stays unchanged.
- Let consist of squares. The new squares get numbers from to . If square has a smaller number than square in , then the square corresponding to has a smaller number than the square corresponding to .

You are given the configuration of the historical part and the development data for years. Answer queries that ask for the shortest distance between two squares.
Input
The first line contains three integers , and : the number of squares in the historical part, the number of years the new part was built, and the number of queries ().
Each of the next lines contains two integers and , the numbers of two squares in the historical part connected by an avenue (; ). It is guaranteed that the squares and avenues form a tree. The main square, the root of the tree, has number 1.
Each of the next lines contains two integers and : the number of the source square in the historical part and the number of the square to which the copy is attached (; , and does not exceed the number of squares at the start of the corresponding year).
Each of the next lines contains two integers and , the numbers of the squares whose distance must be found. Let be the total number of squares after years of construction. Then .
Output
For each query, print one integer: the shortest distance between the corresponding squares.