/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 300000;

int t;

int n;

int aParent[N_MAX + 2];
int bParent[N_MAX + 2];

vector <int> aSons[N_MAX + 2];
vector <int> bSons[N_MAX + 2];

int L[N_MAX + 2], R[N_MAX + 2];
int curr;

void dfs (int u)
{
    curr++;
    L[u] = R[u] = curr;
    for(int v : bSons[u])
    {
        dfs(v);
        R[u] = max(R[u], R[v]);
    }
}

struct SGTNode
{
    int maxVal;
    int lazy;
};

SGTNode join (const SGTNode &u, const SGTNode &v)
{
    return SGTNode{max(u.maxVal, v.maxVal), -1};
}

SGTNode SGT[N_MAX * 4 + 2];

int currAnswer;

struct Change
{
    SGTNode *ptr;
    SGTNode val;
    int prAnswer;
    int time;
};

vector <Change> changes;

struct ChangeBIT
{
    int *ptr;
    int val;
    int prAnswer;
    int time;
};

vector <ChangeBIT> changesBIT;

int currTime;

void pushChange (int node)
{
    changes.push_back(Change{&(SGT[node]), SGT[node], currAnswer, currTime});
}

void undo ()
{
    while(changes.empty() == false && changes.back().time > currTime)
    {
        *changes.back().ptr = changes.back().val;
        currAnswer = changes.back().prAnswer;
        changes.pop_back();
    }
    while(changesBIT.empty() == false && changesBIT.back().time > currTime)
    {
        *changesBIT.back().ptr = changesBIT.back().val;
        currAnswer = changesBIT.back().prAnswer;
        changesBIT.pop_back();
    }
}

void split (int node)
{
    if(SGT[node].lazy == -1)
        return;
    pushChange(node);
    int lSon = node * 2, rSon = node * 2 + 1;
    pushChange(lSon);
    pushChange(rSon);
    SGT[lSon].maxVal = SGT[node].lazy;
    SGT[lSon].lazy = SGT[node].lazy;
    SGT[rSon].maxVal = SGT[node].lazy;
    SGT[rSon].lazy = SGT[node].lazy;
    SGT[node].lazy = -1;
}

void build (int node, int l, int r)
{
    if(l == r)
    {
        SGT[node].maxVal = 0;
        SGT[node].lazy = -1;
        return;
    }
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    build(lSon, l, mid);
    build(rSon, mid + 1, r);
    SGT[node] = join(SGT[lSon], SGT[rSon]);
}
void build ()
{
    build(1, 1, n);
}

void update (int node, int l, int r, int ul, int ur, int uval)
{
    if(ul <= l && r <= ur)
    {
        pushChange(node);
        SGT[node].maxVal = uval;
        SGT[node].lazy = uval;
        return;
    }
    split(node);
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    if(ul <= mid)
        update(lSon, l, mid, ul, ur, uval);
    if(mid + 1 <= ur)
        update(rSon, mid + 1, r, ul, ur, uval);
    pushChange(node);
    SGT[node] = join(SGT[lSon], SGT[rSon]);
}
void update (int ul, int ur, int uval)
{
    update(1, 1, n, ul, ur, uval);
}

int query (int node, int l, int r, int qpos)
{
    if(l == r)
        return SGT[node].maxVal;
    split(node);
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    if(qpos <= mid)
        return query(lSon, l, mid, qpos);
    else
        return query(rSon, mid + 1, r, qpos);
}
int query (int qpos)
{
    return query(1, 1, n, qpos);
}

int BIT[N_MAX + 2];

void updateBIT (int pos, int val)
{
    for(int i = pos; i <= n; i += i & -i)
    {
        changesBIT.push_back(ChangeBIT{&(BIT[i]), BIT[i], currAnswer, currTime});
        BIT[i] += val;
    }
}

int queryBIT (int pos)
{
    int answer = 0;
    for(int i = pos; i >= 1; i -= i & -i)
        answer += BIT[i];
    return answer;
}

void del (int u)
{
    update(L[u], R[u], 0);
    updateBIT(L[u], -1);
    currAnswer--;
}

void add (int u)
{
    update(L[u], R[u], u);
    updateBIT(L[u], +1);
    currAnswer++;
}

void push (int u)
{
    if(queryBIT(R[u]) - queryBIT(L[u] - 1) > 0)
        return;
    int q = query(L[u]);
    if(q > 0)
        del(q);
    add(u);
}

int answer;

void solve (int u)
{
    currTime++;
    push(u);
    answer = max(answer, currAnswer);
    for(int v : aSons[u])
    {
        solve(v);
    }
    currTime--;
    undo();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 2; i <= n; i++)
        {
            cin >> aParent[i];
            aSons[aParent[i]].push_back(i);
        }
        for(int i = 2; i <= n; i++)
        {
            cin >> bParent[i];
            bSons[bParent[i]].push_back(i);
        }
        build();
        for(int i = 1; i <= n; i++)
            BIT[i] = 0;
        curr = 0;
        dfs(1);
        answer = 0;
        currAnswer = 0;
        currTime = 0;
        solve(1);
        cout << answer << "\n";
        for(int i = 1; i <= n; i++)
        {
            aSons[i].clear();
            bSons[i].clear();
        }
        changes.clear();
        changesBIT.clear();
    }
    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
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 300000;

int t;

int n;

int aParent[N_MAX + 2];
int bParent[N_MAX + 2];

vector <int> aSons[N_MAX + 2];
vector <int> bSons[N_MAX + 2];

int L[N_MAX + 2], R[N_MAX + 2];
int curr;

void dfs (int u)
{
    curr++;
    L[u] = R[u] = curr;
    for(int v : bSons[u])
    {
        dfs(v);
        R[u] = max(R[u], R[v]);
    }
}

struct SGTNode
{
    int maxVal;
    int lazy;
};

SGTNode join (const SGTNode &u, const SGTNode &v)
{
    return SGTNode{max(u.maxVal, v.maxVal), -1};
}

SGTNode SGT[N_MAX * 4 + 2];

int currAnswer;

struct Change
{
    SGTNode *ptr;
    SGTNode val;
    int prAnswer;
    int time;
};

vector <Change> changes;

struct ChangeBIT
{
    int *ptr;
    int val;
    int prAnswer;
    int time;
};

vector <ChangeBIT> changesBIT;

int currTime;

void pushChange (int node)
{
    changes.push_back(Change{&(SGT[node]), SGT[node], currAnswer, currTime});
}

void undo ()
{
    while(changes.empty() == false && changes.back().time > currTime)
    {
        *changes.back().ptr = changes.back().val;
        currAnswer = changes.back().prAnswer;
        changes.pop_back();
    }
    while(changesBIT.empty() == false && changesBIT.back().time > currTime)
    {
        *changesBIT.back().ptr = changesBIT.back().val;
        currAnswer = changesBIT.back().prAnswer;
        changesBIT.pop_back();
    }
}

void split (int node)
{
    if(SGT[node].lazy == -1)
        return;
    pushChange(node);
    int lSon = node * 2, rSon = node * 2 + 1;
    pushChange(lSon);
    pushChange(rSon);
    SGT[lSon].maxVal = SGT[node].lazy;
    SGT[lSon].lazy = SGT[node].lazy;
    SGT[rSon].maxVal = SGT[node].lazy;
    SGT[rSon].lazy = SGT[node].lazy;
    SGT[node].lazy = -1;
}

void build (int node, int l, int r)
{
    if(l == r)
    {
        SGT[node].maxVal = 0;
        SGT[node].lazy = -1;
        return;
    }
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    build(lSon, l, mid);
    build(rSon, mid + 1, r);
    SGT[node] = join(SGT[lSon], SGT[rSon]);
}
void build ()
{
    build(1, 1, n);
}

void update (int node, int l, int r, int ul, int ur, int uval)
{
    if(ul <= l && r <= ur)
    {
        pushChange(node);
        SGT[node].maxVal = uval;
        SGT[node].lazy = uval;
        return;
    }
    split(node);
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    if(ul <= mid)
        update(lSon, l, mid, ul, ur, uval);
    if(mid + 1 <= ur)
        update(rSon, mid + 1, r, ul, ur, uval);
    pushChange(node);
    SGT[node] = join(SGT[lSon], SGT[rSon]);
}
void update (int ul, int ur, int uval)
{
    update(1, 1, n, ul, ur, uval);
}

int query (int node, int l, int r, int qpos)
{
    if(l == r)
        return SGT[node].maxVal;
    split(node);
    int mid = (l + r) / 2;
    int lSon = node * 2, rSon = node * 2 + 1;
    if(qpos <= mid)
        return query(lSon, l, mid, qpos);
    else
        return query(rSon, mid + 1, r, qpos);
}
int query (int qpos)
{
    return query(1, 1, n, qpos);
}

int BIT[N_MAX + 2];

void updateBIT (int pos, int val)
{
    for(int i = pos; i <= n; i += i & -i)
    {
        changesBIT.push_back(ChangeBIT{&(BIT[i]), BIT[i], currAnswer, currTime});
        BIT[i] += val;
    }
}

int queryBIT (int pos)
{
    int answer = 0;
    for(int i = pos; i >= 1; i -= i & -i)
        answer += BIT[i];
    return answer;
}

void del (int u)
{
    update(L[u], R[u], 0);
    updateBIT(L[u], -1);
    currAnswer--;
}

void add (int u)
{
    update(L[u], R[u], u);
    updateBIT(L[u], +1);
    currAnswer++;
}

void push (int u)
{
    if(queryBIT(R[u]) - queryBIT(L[u] - 1) > 0)
        return;
    int q = query(L[u]);
    if(q > 0)
        del(q);
    add(u);
}

int answer;

void solve (int u)
{
    currTime++;
    push(u);
    answer = max(answer, currAnswer);
    for(int v : aSons[u])
    {
        solve(v);
    }
    currTime--;
    undo();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 2; i <= n; i++)
        {
            cin >> aParent[i];
            aSons[aParent[i]].push_back(i);
        }
        for(int i = 2; i <= n; i++)
        {
            cin >> bParent[i];
            bSons[bParent[i]].push_back(i);
        }
        build();
        for(int i = 1; i <= n; i++)
            BIT[i] = 0;
        curr = 0;
        dfs(1);
        answer = 0;
        currAnswer = 0;
        currTime = 0;
        solve(1);
        cout << answer << "\n";
        for(int i = 1; i <= n; i++)
        {
            aSons[i].clear();
            bSons[i].clear();
        }
        changes.clear();
        changesBIT.clear();
    }
    return 0;
}

```