CF-2214I•Codeforces

You Are a Robot

*special

There is a track system consisting of nn intersections, numbered from 11 to nn. The track forms a tree rooted at intersection 11. An unstoppable trolley starts at intersection 11 and moves along the edges of the tree.

Each edge, corresponding to a track segment, contains one of the following:

  • a human,
  • a robot,
  • nothing.

You are a robot, and all robots share a unified mind. You can control the direction of the trolley at any intersection it arrives at.

The trolley stops when there are no further directions it can take. Determine the intersection at which the trolley will stop.

If there are multiple possible answers, you may output any.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of intersections.

The second line of each test case contains n−1n - 1 integers p2,p3,…,pnp_2, p_3, \ldots, p_n (1≤pi<i1 \le p_i \lt i), where pip_i denotes the parent of intersection ii in the tree.

The third line of each test case contains n−1n - 1 integers a2,a3,…,ana_2, a_3, \ldots, a_n (0≤ai≤20 \le a_i \le 2), where aia_i describes the type of the track segment between node pip_i and node ii:

  • 00 denotes an empty segment,
  • 11 denotes a human,
  • 22 denotes a robot.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output a single integer denoting a possible answer. If there are multiple possible answers, you may output any.

Sample 1
Input
3
4
1 2 3
0 1 2
5
1 1 2 3
0 1 2 2
5
1 1 2 2
0 1 2 1
Output
4
4
4

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments