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 CPP):

Solution:
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 3e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
vector<vector<int> > tgraph;
queue<int> que;

int A[MAXN];
int B[MAXN];
int subtree[MAXN];
int top[MAXN];
int par[MAXN];

int in[MAXN];
int out[MAXN];

int mxtree[MAXN*4];
int tree[MAXN*4];
int ans[MAXN];
int er[MAXN];

int seq = 0;

int base = 1;

void getsub(int here)
{
    int there;

    subtree[here] = 1;

    for(int i=0;i<tgraph[here].size();i++){
        there = tgraph[here][i];
        getsub(there);
        subtree[here]+=subtree[there];

        if(subtree[tgraph[here][0]]<subtree[there]){
            swap(tgraph[here][0],tgraph[here][i]);
        }
    }

    return;
}

void gettop(int here)
{
    int there;

    in[here] = seq;
    seq++;

    for(int i=0;i<tgraph[here].size();i++){
        there = tgraph[here][i];
        if(!i)top[there] = top[here];
        else top[there] = there;
        par[there] = here;
        gettop(there);
    }

    out[here] = seq-1;

    return;
}

int getpar(int here)
{
    int L,R;
    int tt;
    int mx = -INF;

    while(here){
        tt = top[here];
        L = base+in[tt];
        R = base+in[here];

        while(L<=R){
            if(L&1){
                mx = max(mx,mxtree[L]);
                L++;
            }
            if(!(R&1)){
                mx = max(mx,mxtree[R]);
                R--;
            }
            L>>=1; R>>=1;
        }

        if(mx!=-INF){
            break;
        }
        here = par[tt];
    }

    if(mx==-INF)return -1;
    else return mx;
}

void myadd(int here)
{
    int tmp = base+in[here];
    mxtree[tmp] = here;
    tree[tmp] = 1;
    tmp>>=1;
    while(tmp){
        mxtree[tmp] = max(mxtree[(tmp<<1)],mxtree[(tmp<<1)|1]);
        tree[tmp]++;
        tmp>>=1;
    }

    return;
}

void myer(int here)
{
    int tmp = base+in[here];
    mxtree[tmp] = -INF;
    tree[tmp] = 0;
    tmp>>=1;
    while(tmp){
        mxtree[tmp] = max(mxtree[(tmp<<1)],mxtree[(tmp<<1)|1]);
        tree[tmp]--;
        tmp>>=1;
    }

    return;
}


void solve(int here,int v)
{
    int there;

    int tmp;
    int L = base+in[here];
    int R = base+out[here];

    int sum = 0;

    while(L<=R){
        if(L&1){
            sum+=tree[L];
            L++;
        }
        if(!(R&1)){
            sum+=tree[R];
            R--;
        }
        L>>=1; R>>=1;
    }

    if(!sum){

        int p = getpar(here);

        if(p==-1){
            v++;
        }
        else {
            myer(p);
        }
        myadd(here);
        er[here] = p;
    }
    else {
        er[here] = -1;
    }

    ans[here] = v;

    for(int i=0;i<graph[here].size();i++){
        there = graph[here][i];
        solve(there,v);
    }

    if(!sum){
        myer(here);
        if(er[here]!=-1)myadd(er[here]);
    }

    return;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;
    int res = 0;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>tc;

    while(tc--){

        cin>>n;

        for(int i=2;i<=n;i++){
            cin>>A[i];
        }
        for(int i=2;i<=n;i++){
            cin>>B[i];
        }

        graph = vector<vector<int> > (n+1);
        tgraph = vector<vector<int> > (n+1);

        for(int i=2;i<=n;i++){
            graph[A[i]].push_back(i);
            tgraph[B[i]].push_back(i);
        }
        seq = 0;

        getsub(1);
        top[1] = 1;
        gettop(1);

        base = 1;
        for(;base<n;base<<=1);

        for(int i=1;i<(base<<1);i++){
            tree[i] = 0;
            mxtree[i] = -INF;
        }

        solve(1,0);

        res = 0;
        for(int i=1;i<=n;i++){
            res = max(res,ans[i]);
        }
        cout<<res<<"\n";
    }

    return 0;
}