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

public class CF_1528_C{
    //SOLUTION BEGIN
    int B = 18;
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int N = ni();
        int[] from = new int[N-1], to = new int[N-1];
        for(int i = 0; i< N-1; i++){
            from[i] = ni()-1;
            to[i] = i+1;
        }
        int[][] g1 = make(N, N-1, from, to, true);
        for(int i = 0; i< N-1; i++){
            from[i] = ni()-1;
            to[i] = i+1;
        }
        int[][] g2 = make(N, N-1, from, to, true);
        int[] eu = new int[N], st = new int[N], en = new int[N];
        time = -1;
        pre(g2, st, en, 0, -1);
        MinTree min = new MinTree(N);
        MaxTree max = new MaxTree(N);
        min.update(0, N-1, -1);
        max.update(0, N-1, -1);
        pn(dfs(g1, min, max, st, en, 0, -1, 0));
    }
    int dfs(int[][] g1, MinTree min, MaxTree max, int[] st, int[] en, int u, int p, int curCount) throws Exception{

       int swapInd = -1;
       boolean add = false;
       if(min.sum(st[u], en[u]) >= 0){
           int anc = (int)min.sum(st[u], en[u]);
           swapInd = anc;
           min.update(st[anc], en[anc], -1);
           max.update(st[anc], en[anc], -1);

           min.update(st[u], en[u], u);
           max.update(st[u], en[u], u);
           add = true;
       }
       if(max.sum(st[u], en[u]) == -1){
           add = true;
           min.update(st[u], en[u], u);
           max.update(st[u], en[u], u);
           curCount++;
       }
       int ans = curCount;
       for(int v:g1[u]){
           if(v == p)continue;
           ans = Math.max(ans, dfs(g1, min, max, st, en, v, u, curCount));
       }
       if(add){
           min.update(st[u], en[u], -1);
           max.update(st[u], en[u], -1);
       }
       if(swapInd != -1){
           min.update(st[swapInd], en[swapInd], swapInd);
           max.update(st[swapInd], en[swapInd], swapInd);
       }
       return ans;
    }
    int time = -1;
    void pre(int[][] g, int[] st, int[] en, int u, int p){
//        eu[++time] = u;
        time++;
        st[u] = time;
        for(int v:g[u])if(v != p)pre(g, st, en, v, u);
        en[u] = time;
    }
    class SegmentTreeFast {

        // Modify the following 5 methods to implement your custom operations on the tree.
        // This example implements Add/Sum operations. Operations like Add/Max, Set/Max can also be implemented.
        int modifyOperation(int x, int y) {
            return x + y;
        }

        // query (or combine) operation
        int queryOperation(int leftValue, int rightValue) {
            return leftValue + rightValue;
        }

        int deltaEffectOnSegment(int delta, int segmentLength) {
            if (delta == getNeutralDelta()) return getNeutralDelta();
            // Here you must write a fast equivalent of following slow code:
            // int result = delta;
            // for (int i = 1; i < segmentLength; i++) result = queryOperation(result, delta);
            // return result;
            return delta * segmentLength;
        }

        int getNeutralDelta() {
            return 0;
        }

        int getInitValue() {
            return 0;
        }

        // generic code
        int[] value;
        int[] delta; // delta[i] affects value[i], delta[2*i+1] and delta[2*i+2]

        int joinValueWithDelta(int value, int delta) {
            if (delta == getNeutralDelta()) return value;
            return modifyOperation(value, delta);
        }

        int joinDeltas(int delta1, int delta2) {
            if (delta1 == getNeutralDelta()) return delta2;
            if (delta2 == getNeutralDelta()) return delta1;
            return modifyOperation(delta1, delta2);
        }

        void pushDelta(int i) {
            int d = 0;
            for (; (i >> d) > 0; d++) {
            }
            for (d -= 2; d >= 0; d--) {
                int x = i >> d;
                value[x >> 1] = joinNodeValueWithDelta(x >> 1, 1 << (d + 1));
                delta[x] = joinDeltas(delta[x], delta[x >> 1]);
                delta[x ^ 1] = joinDeltas(delta[x ^ 1], delta[x >> 1]);
                delta[x >> 1] = getNeutralDelta();
            }
        }

        public SegmentTreeFast(int n) {
            value = new int[2 * n];
            for (int i = 0; i < n; i++) {
                value[i + n] = getInitValue();
            }
            for (int i = 2 * n - 1; i > 1; i -= 2) {
                value[i >> 1] = queryOperation(value[i], value[i ^ 1]);
            }
            delta = new int[2 * n];
            Arrays.fill(delta, getNeutralDelta());
        }

        int joinNodeValueWithDelta(int i, int len) {
            return joinValueWithDelta(value[i], deltaEffectOnSegment(delta[i], len));
        }

        public int query(int from, int to) {
            from += value.length >> 1;
            to += value.length >> 1;
            pushDelta(from);
            pushDelta(to);
            int res = 0;
            boolean found = false;
            for (int len = 1; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1, len <<= 1) {
                if ((from & 1) != 0) {
                    res = found ? queryOperation(res, joinNodeValueWithDelta(from, len)) : joinNodeValueWithDelta(from, len);
                    found = true;
                }
                if ((to & 1) == 0) {
                    res = found ? queryOperation(res, joinNodeValueWithDelta(to, len)) : joinNodeValueWithDelta(to, len);
                    found = true;
                }
            }
            if (!found) throw new RuntimeException();
            return res;
        }

        public void modify(int from, int to, int delta) {
            from += value.length >> 1;
            to += value.length >> 1;
            pushDelta(from);
            pushDelta(to);
            int a = from;
            int b = to;
            for (; from <= to; from = (from + 1) >> 1, to = (to - 1) >> 1) {
                if ((from & 1) != 0) {
                    this.delta[from] = joinDeltas(this.delta[from], delta);
                }
                if ((to & 1) == 0) {
                    this.delta[to] = joinDeltas(this.delta[to], delta);
                }
            }
            for (int i = a, len = 1; i > 1; i >>= 1, len <<= 1) {
                value[i >> 1] = queryOperation(joinNodeValueWithDelta(i, len), joinNodeValueWithDelta(i ^ 1, len));
            }
            for (int i = b, len = 1; i > 1; i >>= 1, len <<= 1) {
                value[i >> 1] = queryOperation(joinNodeValueWithDelta(i, len), joinNodeValueWithDelta(i ^ 1, len));
            }
        }
    }
    class MinTree {
        int m = 1;
        long[] t, lazy;
        public MinTree(int n){
            while(m<n)m<<=1;
            t = new long[m<<1];
            lazy = new long[m<<1];
            Arrays.fill(t, IINF);
            Arrays.fill(lazy, IINF);
        }
        //EDIT
        private void push(int i, int ll, int rr){
            if(lazy[i] != IINF){
                t[i] = lazy[i];
                if(i < m){
                    lazy[i<<1] = lazy[i];
                    lazy[i<<1|1] = lazy[i];
                }
                lazy[i] = IINF;
            }
        }
        public void update(int l, int r, long x){u(l, r, 0, m-1, 1, x);}
        public long sum(int l, int r){return s(l, r, 0, m-1, 1);}

        private void u(int l, int r, int ll, int rr, int i, long x){
            push(i, ll, rr);
            if(l == ll && r == rr){
                lazy[i] = x;//EDIT
                push(i, ll, rr);return;
            }
            int mid = (ll+rr)/2;
            if(r <= mid){
                u(l, r, ll, mid, i<<1, x);
                push(i<<1|1, mid+1, rr);
            }else if(l > mid){
                push(i<<1, ll, mid);
                u(l, r, mid+1, rr, i<<1|1, x);
            }else{
                u(l, mid, ll, mid, i<<1, x);
                u(mid+1, r, mid+1, rr, i<<1|1, x);
            }
            t[i] = Math.min(t[i<<1], t[i<<1|1]);
        }
        private long s(int l, int r, int ll, int rr, int i){
            push(i, ll, rr);
            if(l == ll && r == rr)return t[i];
            int mid = (ll+rr)/2;
            if(r <= mid)return s(l ,r, ll, mid, i<<1);
            else if(l > mid)return s(l, r, mid+1, rr, i<<1|1);
            else return Math.min(s(l, mid, ll, mid, i<<1), s(mid+1, r, mid+1, rr, i<<1|1));
        }
    }
    class MaxTree {
        int m = 1;
        long[] t, lazy;
        public MaxTree(int n){
            while(m<n)m<<=1;
            t = new long[m<<1];
            lazy = new long[m<<1];
            Arrays.fill(t, -IINF);
            Arrays.fill(lazy, -IINF);
        }
        //EDIT
        private void push(int i, int ll, int rr){
            if(lazy[i] != -IINF){
                t[i] = lazy[i];
                if(i < m){
                    lazy[i<<1] = lazy[i];
                    lazy[i<<1|1] = lazy[i];
                }
                lazy[i] = -IINF;
            }
        }
        public void update(int l, int r, long x){u(l, r, 0, m-1, 1, x);}
        public long sum(int l, int r){return s(l, r, 0, m-1, 1);}

        private void u(int l, int r, int ll, int rr, int i, long x){
            push(i, ll, rr);
            if(l == ll && r == rr){
                lazy[i] = x;//EDIT
                push(i, ll, rr);return;
            }
            int mid = (ll+rr)/2;
            if(r <= mid){
                u(l, r, ll, mid, i<<1, x);
                push(i<<1|1, mid+1, rr);
            }else if(l > mid){
                push(i<<1, ll, mid);
                u(l, r, mid+1, rr, i<<1|1, x);
            }else{
                u(l, mid, ll, mid, i<<1, x);
                u(mid+1, r, mid+1, rr, i<<1|1, x);
            }
            t[i] = Math.max(t[i<<1], t[i<<1|1]);
        }
        private long s(int l, int r, int ll, int rr, int i){
            push(i, ll, rr);
            if(l == ll && r == rr)return t[i];
            int mid = (ll+rr)/2;
            if(r <= mid)return s(l ,r, ll, mid, i<<1);
            else if(l > mid)return s(l, r, mid+1, rr, i<<1|1);
            else return Math.max(s(l, mid, ll, mid, i<<1), s(mid+1, r, mid+1, rr, i<<1|1));
        }
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
    final long IINF = (long)1e17;
    final int INF = (int)1e9+2;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = true, memory = true, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if (fileIO) {
            in = new FastReader("");
            out = new PrintWriter("");
        } else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = multipleTC? ni():1;
        pre();
        for (int t = 1; t <= T; t++) solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis() - ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1528_C().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
        else new CF_1528_C().run();
    }
    int[][] make(int n, int e, int[] from, int[] to, boolean f){
        int[][] g = new int[n][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            if(f)g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
        int[][][] g = new int[n][][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
            if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
        }
        return g;
    }
    int[][] make(int n, int[] par, boolean f){
        int[][] g = new int[n][];
        int[] cnt = new int[n];
        for(int i = 1; i< n; i++)cnt[par[i]]++;
        if(f)for(int i = 1; i< n; i++)cnt[i]++;
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 1; i< n-1; i++){
            g[par[i]][--cnt[par[i]]] = i;
            if(f)g[i][--cnt[i]] = par[i];
        }
        return g;
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object... o){for(Object oo:o)out.print(oo+" ");}
    void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));}
    void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}