Parent#630

Parent

1 second
128 megabytes
Medium (≈1350)

Write a program that determines whether one of two given vertices in a tree is a parent of the other.

Input

The first line contains one integer n~(1 \le n \le 10^5) — the number of vertices in the tree.

The second line contains integers, where the -th number represents the parent of the vertex numbered . If the value is zero, the vertex is the root of the tree.

The third line contains an integer m~(1 \le m \le 10^5) — the number of queries.

Each of the following lines contains two distinct integers and b~(1 \le a, b \le n), representing a query.

Output

For each of the queries, print in a separate line if vertex is a parent of vertex , and otherwise.

Examples

Example 1

Loading
Loading