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:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.SortedSet;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int ans;
        SortedSet<Integer> set = new TreeSet<>();
        int[] kickedBy;
        int[] timeIn;
        int[] timeOut;
        int[] order;
        int globalTime;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int numTests = in.nextInt();
            for (int test = 0; test < numTests; test++) {
                int n = in.nextInt();
                int[] a = new int[n];
                for (int i = 1; i < n; i++) {
                    a[i] = in.nextInt() - 1;
                }
                int[] b = new int[n];
                for (int i = 1; i < n; i++) {
                    b[i] = in.nextInt() - 1;
                }

                Graph ga = new Graph(n);
                for (int i = 1; i < n; i++) {
                    ga.addEdge(a[i], i);
                }

                Graph gb = new Graph(n);
                for (int i = 1; i < n; i++) {
                    gb.addEdge(b[i], i);
                }

                timeIn = new int[n];
                timeOut = new int[n];
                order = new int[n];
                globalTime = 0;
                dfsTimes(gb, 0);

                set.clear();
                kickedBy = new int[n];
                ans = 0;
                dfs(ga, 0);
                out.println(ans);
            }
        }

        private void dfs(Graph ga, int v) {
            addSegment(v);
            ans = Math.max(ans, set.size());
            for (int e = ga.firstEdge[v]; e >= 0; e = ga.edgeNxt[e]) {
                int u = ga.edgeDst[e];
                dfs(ga, u);
            }
            removeSegment(v);
        }

        private void addSegment(int i) {
            // [l, r)
            int l = timeIn[i];
            int r = timeOut[i];

            SortedSet<Integer> hs = set.headSet(l);
            if (!hs.isEmpty()) {
                int j = order[hs.last()];
                if (isAncestor(j, i)) {
                    set.remove(timeIn[j]);
                    set.add(l);
                    kickedBy[i] = j;
                    return;
                }
            }
            SortedSet<Integer> ts = set.tailSet(l);
            if (!ts.isEmpty()) {
                int j = order[ts.first()];
                if (isAncestor(i, j)) {
                    return;
                }
            }
            kickedBy[i] = -1;
            set.add(l);
        }

        private void removeSegment(int i) {
            int l = timeIn[i];
            int r = timeOut[i];
            if (!set.contains(l)) {
                return;
            }
            set.remove(l);
            if (kickedBy[i] >= 0) {
                set.add(timeIn[kickedBy[i]]);
            }
        }

        private void dfsTimes(Graph g, int v) {
            order[globalTime] = v;
            timeIn[v] = globalTime++;
            for (int e = g.firstEdge[v]; e >= 0; e = g.edgeNxt[e]) {
                int u = g.edgeDst[e];
                dfsTimes(g, u);
            }
            timeOut[v] = globalTime;
        }

        private boolean isAncestor(int parent, int son) {
            return timeIn[parent] <= timeIn[son] && timeOut[son] <= timeOut[parent];
        }

        class Graph {
            int n;
            int[] firstEdge;
            int[] edgeDst;
            int[] edgeNxt;
            int numEdges;

            Graph(int n) {
                this.n = n;
                firstEdge = new int[n];
                Arrays.fill(firstEdge, -1);
                final int initialCapacity = 2 * n - 2;
                edgeDst = new int[initialCapacity];
                edgeNxt = new int[initialCapacity];
                numEdges = 0;
            }

            void addEdge(int a, int b) {
                int e = numEdges++;
                if (e >= edgeDst.length) {
                    reallocate();
                }
                edgeDst[e] = b;
                edgeNxt[e] = firstEdge[a];
                firstEdge[a] = e;
            }

            private void reallocate() {
                int k = edgeDst.length;
                edgeDst = Arrays.copyOf(edgeDst, 3 * k / 2);
                edgeNxt = Arrays.copyOf(edgeNxt, 3 * k / 2);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}