/*
K.D. Vinit  |,,|
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 3e5+2;
vector<int> adj1[N], adj2[N];

int strt[N];
int nd[N];
int ans;

set< pair<int, int> > st;
int rep[N];

bool check_sub(int v)
{
    pair<int, int> tmp = {strt[v], v};
    auto nxt = *st.upper_bound(tmp);
    int ind = nxt.second;

    if(nd[ind]<nd[v]) return true;
    else return false;
}

int ances(int v)
{
    pair<int, int> tmp = {strt[v], v};
    auto nxt = st.upper_bound(tmp); nxt--;
    auto cur = *nxt;
    int ind = cur.second;

    if(nd[ind]>nd[v]) return ind;
    else return 0;
}

void Add_Node(int v)
{
    if(check_sub(v)) return;

    int pre = ances(v);
    st.insert({strt[v], v});

    if(pre==0) return;
    rep[v] = pre;
    st.erase({strt[pre], pre});
}

void Delete_Node(int v)
{
    st.erase({strt[v], v});
    int x = rep[v];
    if(x!=0) st.insert({strt[x], x});
}

void Evaluate()
{
    int tmp = st.size();
    ans = max(ans, tmp);
}

void DFS1(int chi, int par, int& time)
{
    strt[chi] = ++time;
    for(auto x: adj2[chi])
    {
        if(x==par) continue;
        DFS1(x, chi, time);
    }
    nd[chi] = ++time;
}

void DFS2(int chi, int par)
{
    Add_Node(chi);
    for(auto x: adj1[chi])
    {
        if(x==par) continue;
        DFS2(x, chi);
    }
    if(adj1[chi].size()==1) Evaluate();
    Delete_Node(chi);
}

void solve()
{
    int n;
    cin>>n;

    //Reset Adjacency List
    for(int i=1; i<=n; i++) { adj1[i].clear(); adj2[i].clear(); }

    //Take Input
    for(int i=2; i<=n; i++) { int p; cin>>p; adj1[p].push_back(i); adj1[i].push_back(p); }
    for(int i=2; i<=n; i++) { int p; cin>>p; adj2[p].push_back(i); adj2[i].push_back(p); }

    //Euler's Tour
    int time = 0;
    DFS1(1, -1, time);

    //Preparation for DFS
    ans=0;  st.clear();
    strt[n+1] = 2*n+4; nd[n+1] = 2*n+5; st.insert({strt[n+1], n+1});
    strt[0] = -2; nd[0] = -1; st.insert({strt[0], 0});
    for(int i=1; i<=n; i++) rep[i]=0;

    //DFS on first tree
    DFS2(1, -1);
    cout<<ans-2<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t; cin>>t;
    while(t--) solve();
    return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following 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\}.

### Response

```cpp
/*
K.D. Vinit  |,,|
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 3e5+2;
vector<int> adj1[N], adj2[N];

int strt[N];
int nd[N];
int ans;

set< pair<int, int> > st;
int rep[N];

bool check_sub(int v)
{
    pair<int, int> tmp = {strt[v], v};
    auto nxt = *st.upper_bound(tmp);
    int ind = nxt.second;

    if(nd[ind]<nd[v]) return true;
    else return false;
}

int ances(int v)
{
    pair<int, int> tmp = {strt[v], v};
    auto nxt = st.upper_bound(tmp); nxt--;
    auto cur = *nxt;
    int ind = cur.second;

    if(nd[ind]>nd[v]) return ind;
    else return 0;
}

void Add_Node(int v)
{
    if(check_sub(v)) return;

    int pre = ances(v);
    st.insert({strt[v], v});

    if(pre==0) return;
    rep[v] = pre;
    st.erase({strt[pre], pre});
}

void Delete_Node(int v)
{
    st.erase({strt[v], v});
    int x = rep[v];
    if(x!=0) st.insert({strt[x], x});
}

void Evaluate()
{
    int tmp = st.size();
    ans = max(ans, tmp);
}

void DFS1(int chi, int par, int& time)
{
    strt[chi] = ++time;
    for(auto x: adj2[chi])
    {
        if(x==par) continue;
        DFS1(x, chi, time);
    }
    nd[chi] = ++time;
}

void DFS2(int chi, int par)
{
    Add_Node(chi);
    for(auto x: adj1[chi])
    {
        if(x==par) continue;
        DFS2(x, chi);
    }
    if(adj1[chi].size()==1) Evaluate();
    Delete_Node(chi);
}

void solve()
{
    int n;
    cin>>n;

    //Reset Adjacency List
    for(int i=1; i<=n; i++) { adj1[i].clear(); adj2[i].clear(); }

    //Take Input
    for(int i=2; i<=n; i++) { int p; cin>>p; adj1[p].push_back(i); adj1[i].push_back(p); }
    for(int i=2; i<=n; i++) { int p; cin>>p; adj2[p].push_back(i); adj2[i].push_back(p); }

    //Euler's Tour
    int time = 0;
    DFS1(1, -1, time);

    //Preparation for DFS
    ans=0;  st.clear();
    strt[n+1] = 2*n+4; nd[n+1] = 2*n+5; st.insert({strt[n+1], n+1});
    strt[0] = -2; nd[0] = -1; st.insert({strt[0], 0});
    for(int i=1; i<=n; i++) rep[i]=0;

    //DFS on first tree
    DFS2(1, -1);
    cout<<ans-2<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t; cin>>t;
    while(t--) solve();
    return 0;
}

```