Calculate the distance between two nodes.
For each case, the first line contains a positive integer N (1 <= N <= 1000), denoting the number of node in the tree (labeled from 1 to N). The second line contains exactly N numbers. The first number denotes the parent of node 1, and the second number denotes the parent of node 2 ..., etc. The parent of the root will be labeled as -1.
Then follows multiple lines of query (query < 10000). Each line contains two positive integers A and B. The query is terminated by two zeros.
Do not assume it is a binary tree.
For each case a line, print the case number first, then output the distance between A and B for each query. Each answer should be separated by a single space.