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>
#include <stdlib.h>

using namespace std;

typedef  long long  int ll;
typedef  long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007

ll n, p1[300004],p2[300004],bit1[600004],bit2[600004];

ll st2[300004],fin2[300004], dfscntr2;

vll ch1[300005],ch2[300005];

ll ans,finans;

void dfs(ll st) {
    st2[st] = ++dfscntr2;
    for(ll v : ch2[st]) dfs(v);
    fin2[st] = ++dfscntr2;
}

void updateb1(ll p,ll v){
    for(ll i=p;i<=2*n;i+=(i&-i)) bit1[i] += v;
}
ll qryb1(ll p){
    ll ret=0;
    for(ll i=p;i;i-=(i&-i)) ret+=bit1[i];
    return ret;
}

ll sumb1(ll l, ll r) {
    return qryb1(r) - qryb1(l-1);
}

void updateb2(ll p,ll v){
    for(ll i=p;i<=2*n;i+=(i&-i)) bit2[i] += v;
}
ll qryb2(ll p){
    ll ret=0;
    for(ll i=p;i;i-=(i&-i)) ret+=bit2[i];
    return ret;
}

ll sumb2(ll l, ll r) {
    return qryb2(r) - qryb2(l-1);
}


void findans(ll v) {

    ll curans = ans;
    ll par = 0;
    if (v == 1) {
        ans = 1;
    } else {
        par = sumb2(1, st2[v]-1);
        if(sumb1(st2[v], fin2[v]) == 0) {
            if(!par) ans++;
            else if (sumb1(st2[par], fin2[par]) > 1) ans++;
        }
    }
    if(par) {
        updateb2(st2[par], -par);
        updateb2(fin2[par], par);
    }
    // add
    updateb1(st2[v], 1);
    updateb2(st2[v], v);
    updateb2(fin2[v], -v);


    finans = max(finans, ans);


    for(ll vv : ch1[v]) findans(vv);

    ans = curans;
    // removal

    if(par) {
        updateb2(st2[par], par);
        updateb2(fin2[par], -par);
    }

    updateb1(st2[v], -1);
    updateb2(st2[v], -v);
    updateb2(fin2[v], v);

}

int main() {
    ios :: sync_with_stdio(false); cin.tie(0);

    ll t;cin>>t;while(t--) {
        cin>>n;

        rep(i,1,n) {
            ch1[i].clear();
            ch2[i].clear();
            bit1[i] = bit2[i] = 0;
        }
        dfscntr2 = ans = finans = 0;

        rep(i,2,n) {cin>>p1[i]; ch1[p1[i]].pb(i);}
        rep(i,2,n) {cin>>p2[i]; ch2[p2[i]].pb(i);}

        dfs(1);

        findans(1);
        cout<<finans<<'\n';
    }
}