Natural Tiger Hug University(NTHU) is a good university in Taiwan. Their dooms are quite interesting. For example, the doom for the computer science is a tree, and whole CS students live in there. For a tree structure, there is a root of this tree. Each node except root will have a parent.
In the CS department, there are four popular girls who are called "FOUR HUN" (四夯). The four girls are quite good at finding a problem. Now in their investigation, all CS students are very lazy. If they don't go to another's room by the best way(the best way means that they go to another's room by minimum length). They will be crazy and crash the doom. To prevent this, FOUR HUN want to save the dorm!!!!!!!!!!! But they are so popular that they can't calculate the best way. So they need your help!!!!
They will model each room by numbers(1,2,....) and they will give you many queries that the distance of the rooms they want to calculate. Please give them the answer!!!
The first line in the input is an integer t(t <= 20), which indicate how many cases in the input.
For each case, given an integer n(2 <= n <= 1000), which is how many rooms in CS's dorm. Next line consists of n integers, the first integer is the room on the top of room 1. The second integer is the room on the top of room 2... so on and so forth. Each road between two rooms are bidirected.
Each integer in this line are all from 1 to n, except the root, which is denoted by 0(because there is no room on the top of it). Next line will give you a integer q (q <= 999000), which indicate how many queries the four girls asked. Next q lines each line contains two integer a, b (1 <= a,b <= n, a != b), which are the questions they want to know!!
For each case, output the case number as sample.
For each query, output one line with the minimum distance between two rooms.
Please refer to the sample output.