Ancestor#1941

Ancestor

1 second
128 megabytes
Easy (≈1000)

Given a rooted tree, answer queries of the form: is vertex an ancestor of vertex ?

Input

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

The second line contains integers: the -th of them is the parent of vertex . For the root of the tree, this number is .

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

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

Output

For each query, print on a separate line if vertex is an ancestor of vertex , and otherwise.

Examples

Example 1

Loading
Loading