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.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
 import java.util.*;
public  class realfast implements Runnable 
  {
    private static final int INF = (int) 1e9;
    long in= 1000000007;
    long fac[]= new long[1000001];
    long inv[]=new long[1000001];
    public  void solve() throws IOException 
    {

        //int t = readInt();

        int t = readInt();

        for(int f =0;f<t;f++)
        {
            int n = readInt();

           
            ArrayList<Integer> arr[]= new ArrayList[n+1];
            ArrayList<Integer> brr[]= new ArrayList[n+1];
            for(int i =1;i<=n;i++)
            {
                arr[i]=new ArrayList<Integer>();
            }
            for(int i=1;i<=n;i++)
            {
                brr[i]=new ArrayList<Integer>();
            }
            for(int i=2;i<=n;i++)
            {
                int a= readInt();
                arr[a].add(i);
                arr[i].add(a);
            }
            for(int i=2;i<=n;i++)
            {
                int a= readInt();
                brr[a].add(i);
                brr[i].add(a);
            }

            int in[]=new int[n+1];
            int out1[]=new int[n+1];
            int end[]=new int[2*n+1];
            int timer[]=new int[2];
            int count[]=new int[n+1];
            int seg[]=new int[8*n+8];
            euler(brr,1,0,in,out1,timer,end);

            dfs(arr,1,0,in,out1,seg,end,count);
          
            int max=0;

            for(int i=1;i<=n;i++)
                max=Math.max(max,count[i]);


            out.println(max);




        }
      
             


         



        



    }
    public void dfs(ArrayList<Integer> arr[] , int u , int par , int in[] , int out [] , int seg[], int end[], int count[])
    {
        int n = arr.length-1;
        int a=-1;
        boolean check = false;
        int b = left(seg,1,2*n,0,in[u]);
        int c = left(seg,1,2*n,0,out[u]);
        if(end[b]>out[u])
        {
             delete(seg,1,2*n,0,b);
             a=b;
             check = true;
             add(seg,1,2*n,0,in[u]);
             count[u]=count[par];
        }
        else if(c>in[u]&&end[c]>in[u]&&end[c]<out[u])
        {
             count[u]= count[par];
        }
        else
        {
            check = true;
            add(seg,1,2*n,0,in[u]);
            
            count[u]= count[par]+1;
            
        }

        for(int j =0;j<arr[u].size();j++)
        {
             int v = arr[u].get(j);
             if(v!=par)
             {
                dfs(arr,v,u,in,out,seg,end,count);
             }
        }

        if(check)
            delete(seg,1,2*n,0,in[u]);
        if(a!=-1)
        {
            add(seg,1,2*n,0,a);
        }

    }
    public  void euler(ArrayList<Integer> arr[] ,int i , int par, int in[] , int out[], int timer[], int end[])
    {

             timer[0]++;
             in[i]= timer[0];

             for(int j =0;j<arr[i].size();j++)
             {
                 int v = arr[i].get(j);
                 if(v!=par)
                    euler(arr,v,i,in,out,timer,end);
             }
             timer[0]++;
             out[i]= timer[0];
             end[in[i]]= out[i];

    }

    public int left(int seg[] , int left , int right , int index , int l )
    {
        if(left>l)
            return 0;
        
        if(right<=l)
        {
              return seg[index];
        }

        int mid = left+(right-left)/2;

        return Math.max(left(seg,left,mid,2*index+1,l),left(seg,mid+1,right,2*index+2,l));
    }
    
    public void add(int seg[] , int left , int right , int index, int i)
    {
               if(left==right)
               {
                seg[index]=left;
                return ;
               }

                seg[index]=Math.max(seg[index],i);

               int mid = left+(right-left)/2;
               if(i<=mid)
               add(seg,left,mid,2*index+1,i);
               else
               add(seg,mid+1,right,2*index+2,i);

              
    }
    public void delete(int seg[] , int left , int right, int index, int i )
    {
               if(left==right)
               {
                seg[index]=0;
                return;
               }

               

               int mid = left+(right-left)/2;
               if(i<=mid)
               delete(seg,left,mid,2*index+1,i);
               else
               delete(seg,mid+1,right,2*index+2,i);
               seg[index]=Math.max(seg[2*index+1],seg[2*index+2]);


    }
    
    
   
    public int gcd(int a , int b )
    {
      if(a<b)
      {
        int t =a;
        a=b;
        b=t;
      }
      if(a%b==0)
        return b ;
      return gcd(b,a%b);
    }
    public long pow(long n , long p,long m)
    {
         if(p==0)
            return 1;
        long val = pow(n,p/2,m);;
        val= (val*val)%m;
        if(p%2==0)
            return val;
        else
            return (val*n)%m;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int u ;
    int v;
    
    edge(int u, int v)
    {
       this.u=u;
       this.v=v;
    }
    public int compareTo(edge e)
    {
        return this.v-e.v;
    }
}