Problem: Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1.

Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph on n vertices.

They add an edge between vertices u and v in the memorial graph if both of the following conditions hold: 

  * One of u or v is the ancestor of the other in Soroush's tree. 
  * Neither of u or v is the ancestor of the other in Keshi's tree. 



Here vertex u is considered ancestor of vertex v, if u lies on the path from 1 (the root) to the v.

Popping out of nowhere, Mashtali tried to find the maximum clique in the memorial graph for no reason. He failed because the graph was too big. 

Help Mashtali by finding the size of the maximum clique in the memorial graph.

As a reminder, clique is a subset of vertices of the graph, each two of which are connected by an edge.

Input

The first line contains an integer t (1≤ t≤ 3 ⋅ 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (2≤ n≤ 3 ⋅ 10^5).

The second line of each test case contains n-1 integers a_2, …, a_n (1 ≤ a_i < i), a_i being the parent of the vertex i in Soroush's tree.

The third line of each test case contains n-1 integers b_2, …, b_n (1 ≤ b_i < i), b_i being the parent of the vertex i in Keshi's tree.

It is guaranteed that the given graphs are trees.

It is guaranteed that the sum of n over all test cases doesn't exceed 3 ⋅ 10^5.

Output

For each test case print a single integer — the size of the maximum clique in the memorial graph.

Example

Input


4
4
1 2 3
1 2 3
5
1 2 3 4
1 1 1 1
6
1 1 1 1 2
1 2 1 2 2
7
1 1 3 4 4 5
1 2 1 4 2 5


Output


1
4
1
3

Note

In the first and third test cases, you can pick any vertex.

In the second test case, one of the maximum cliques is \{2, 3, 4, 5\}.

In the fourth test case, one of the maximum cliques is \{3, 4, 6\}.

Solution (in JAVA):

Solution:
/*
bts songs to dance to:
I need U
Run
ON
Filter
I'm fine
 */
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;

public class x1528C
{
    static int[][] edges;
    static int[][] edgesK;
    public static void main(String hi[]) throws Exception
    {
        FastScanner infile = new FastScanner();
        int T = infile.nextInt();
        StringBuilder sb = new StringBuilder();
        while(T-->0)
        {
            int N = infile.nextInt();
            int[] parents1 = infile.nextInts(N-1);
            int[] parents2 = infile.nextInts(N-1);
            edges = new int[N+1][];
            edgesK = new int[N+1][];
            init(N, parents1, edges);
            init(N, parents2, edgesK);
            //get ranges
            ranges = new int[N+1][2];
            time = 1;
            dfs1(1);
            RangeBit bit = new RangeBit(N+N+1);
            res = 1;
            bit.update(ranges[1][0], ranges[1][1], 1);
            dfs(1, bit, 1);
            sb.append(res+"\n");
        }
        System.out.print(sb);
    }
    static int res;
    static int[][] ranges;
    public static void dfs(int curr, RangeBit bit, int val)
    {
        for(int next: edges[curr])
        {
            //System.out.println(curr+"->"+next+" "+val);
            int left = ranges[next][0];
            int right = ranges[next][1];
            if(bit.query(left, right) == 0)
            {
                bit.update(left, right, next);
                res = max(res, val+1);
                dfs(next, bit, val+1);
                bit.update(left, right, -1*next);
            }
            else
            {
                //find ancestor conflict
                int anc = bit.query(left, left);
                if(ranges[anc][0] < left)
                {
                    bit.update(ranges[anc][0], ranges[anc][1], -1*anc);
                    bit.update(left, right, next);
                    dfs(next, bit, val);
                    bit.update(left, right, -1*next);
                    bit.update(ranges[anc][0], ranges[anc][1], anc);
                }
                else
                    dfs(next, bit, curr);
                res = max(res, val);
            }
        }
    }
    static int time;
    public static void dfs1(int curr)
    {
        ranges[curr][0] = time++;
        for(int next: edgesK[curr])
            dfs1(next);
        ranges[curr][1] = time++;
    }
    public static void init(int N, int[] parents, int[][] edges)
    {
        int[] freq = new int[N+1];
        for(int v=0; v < N-1; v++)
            freq[parents[v]]++;
        for(int v=1; v <= N; v++)
            edges[v] = new int[freq[v]];
        for(int v=0; v < N-1; v++)
            edges[parents[v]][--freq[parents[v]]] = v+2;
    }
}
/*
1
5
1 2 3 4
1 1 1 1

 */
/*
upper bound is longest path from root to leaf
define range as in euler tour
find set of "ranges" such that they completely nest, then are completely disjoint

notice in input, u < v if u is above v
for any clique, we can get a chain of ancestors in increasing id
potentially turn into LIS (probably not)

What I should've thought about instead:
Rather than constructing a subset, take a large set and remove nodes from it
We can do this greedy (always remove the ancestor)
 */
class RangeBit
{
    final int[] value;
    final int[] weightedVal;

    public RangeBit(int treeTo)
    {
        value = new int[treeTo+2];
        weightedVal = new int[treeTo+2];
    }
    private void updateHelper(int index, int delta)
    {
        int weightedDelta = index*delta;
        for(int j = index; j < value.length; j += j & -j)
        {
            value[j] += delta;
            weightedVal[j] += weightedDelta;
        }
    }
    public void update(int from, int to, int delta)
    {
        updateHelper(from, delta);
        updateHelper(to + 1, -delta);
    }
    private int query(int to)
    {
        int res = 0;
        int weightedRes = 0;
        for (int j = to; j > 0; j -= j & -j)
        {
            res += value[j];
            weightedRes += weightedVal[j];
        }
        return ((to + 1)*res)-weightedRes;
    }
    public int query(int from, int to)
    {
        if (to < from)
            return 0;
        return query(to) - query(from - 1);
    }
}
class FastScanner
{
    private int BS = 1 << 16;
    private char NC = (char) 0;
    private byte[] buf = new byte[BS];
    private int bId = 0, size = 0;
    private char c = NC;
    private double cnt = 1;
    private BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    private char getChar() {
        while (bId == size) {
            try {
                size = in.read(buf);
            } catch (Exception e) {
                return NC;
            }
            if (size == -1) return NC;
            bId = 0;
        }
        return (char) buf[bId++];
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public int[] nextInts(int N) {
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
        }
        return res;
    }

    public long[] nextLongs(int N) {
        long[] res = new long[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    public long nextLong() {
        cnt = 1;
        boolean neg = false;
        if (c == NC) c = getChar();
        for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
        }
        long res = 0;
        for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
        }
        return neg ? -res : res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c != '.' ? cur : cur + nextLong() / cnt;
    }

    public double[] nextDoubles(int N) {
        double[] res = new double[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c > 32) {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c != '\n') {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if (c > 32) return true;
        while (true) {
            c = getChar();
            if (c == NC) return false;
            else if (c > 32) return true;
        }
    }
}