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.util.*;
import java.io.*;

public class _722 {
    static ArrayList<Integer> [] a;
    static ArrayList<Integer> [] b;
    static int [] in;
    static int [] out;
    static int timer;
    static TreeSet<Pair> set;
    static int ans;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            a = new ArrayList[n];
            b = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                a[i] = new ArrayList<>();
                b[i] = new ArrayList<>();
            }
            for (int i = 1; i < n; i++) {
                int u = sc.nextInt() - 1;
                a[u].add(i);
                a[i].add(u);
            }
            for (int i = 1; i < n; i++) {
                int u = sc.nextInt() - 1;
                b[u].add(i);
                b[i].add(u);
            }
            ans = 0;
            in = new int[n];
            out = new int[n];
            dfs0(0, -1);
            set = new TreeSet<>();
            dfs(0, -1);
            pw.println(ans);
        }
        pw.close();
    }

    static void dfs0(int cur, int par) {
        in[cur] = timer++;
        for (Integer next: b[cur]) {
            if (next != par) {
                dfs0(next, cur);
            }
        }
        out[cur] = timer++;
    }

    // returns whether interval a contains interval b
    static boolean contains(Pair a, Pair b) {
        return a.l <= b.l && a.r >= b.r;
    }

    static void dfs(int cur, int par) {
        Pair interval = new Pair(in[cur], out[cur]);
        Pair lo = set.lower(interval);
        Pair hi = set.higher(interval);
        Pair remove = null;
        Pair add = null;
        if ((lo == null || !contains(lo, interval)) && (hi == null || !contains(interval, hi))) {
            // neither lo nor high contains it
            add = interval;
            set.add(add);
        } else if (lo != null && contains(lo, interval)) {
            // lo contains it
            remove = lo;
            add = interval;
            set.remove(remove);
            set.add(add);
        } else if (hi != null && contains(interval, hi)) {
            // don't do anything
        }
        ans = Math.max(ans, set.size());
        for (Integer next: a[cur]) {
            if (next != par) {
                dfs(next, cur);
            }
        }
        if (add != null) set.remove(add);
        if (remove != null) set.add(remove);
    }


    static class Pair implements Comparable<Pair> {
        int l; int r;
        Pair(int l, int r) {
            this.l = l; this.r = r;
        }

        @Override
        public int compareTo(Pair o) {
            if (l == o.l) return Integer.compare(r, o.r);
            else return Integer.compare(l, o.l);
        }
    }





    static void sort(int[] a) {
        ArrayList<Integer> q = new ArrayList<>();
        for (int i : a) q.add(i);
        Collections.sort(q);
        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
    }

    static void sort(long[] a) {
        ArrayList<Long> q = new ArrayList<>();
        for (long i : a) q.add(i);
        Collections.sort(q);
        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}