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:
/**
  Solves SPOJ HORRIBLE - Horrible Queries
  Range Increment Update, Range Sum Query
**/

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+7;

struct SegTree {
    long long tr[4*N];
    long long lz[4*N];

    ///1. Merge left and right
    int combine (int left, int right) {
        return left + right;
    }

    ///2. Push lazy down and merge lazy
    void propagate(int u, int st, int en) {
        if (!lz[u]) return;
        tr[u] += (en-st+1)*lz[u];
        if (st!=en) {
            lz[2*u] += lz[u];
            lz[2*u+1] += lz[u];
        }
        lz[u] = 0;
    }


    void build(int u, int st, int en) {
        if (st==en) {
            tr[u] = 0;          ///3. Initialize
            lz[u] = 0;
        }
        else {
            int mid = (st+en)/2;
            build(2*u, st, mid);
            build(2*u+1, mid+1, en);
            tr[u] = combine(tr[2*u], tr[2*u+1]);
            lz[u] = 0;              ///3. Initialize
        }
    }

    void update(int u, int st, int en, int l, int r, int x) {
        propagate(u, st, en);
        if (r<st || en<l)  return;
        else if (l<=st && en<=r) {
            lz[u] += x;             ///4. Merge lazy
            propagate(u, st, en);
        }
        else {
            int mid = (st+en)/2;
            update(2*u, st, mid, l, r, x);
            update(2*u+1, mid+1, en, l, r, x);
            tr[u] = combine(tr[2*u], tr[2*u+1]);
        }
    }

    int query(int u, int st, int en, int l, int r) {
        propagate(u, st, en);
        if (r<st || en<l)  return 0;        /// 5. Proper null value
        else if (l<=st && en<=r)    return tr[u];
        else {
            int mid = (st+en)/2;
            return combine(query(2*u, st, mid, l, r), query(2*u+1, mid+1, en, l, r));
        }
    }

    void debug(int u, int st, int en) {
        cout<<"--->"<<u<<" "<<st<<" "<<en<<" "<<tr[u]<<" "<<lz[u]<<endl;
        if (st==en) return;
        int mid = (st+en)/2;
        debug(2*u, st, mid);
        debug(2*u+1, mid+1, en);
    }
} tr[2];

vector<int> adj[2][N];

int st[N], en[N];
int clk = 0;

void dfs1(int u, int p) {
    st[u] = ++clk;
    for (int v: adj[1][u]) {
        if (v == p) continue;
        dfs1(v, u);
    }
    en[u] = clk;
}

int ans = 0;
int n;

int subcount(int u) {
    return tr[1].query(1, 1, n, st[u], en[u]);
}

void dfs2(int u, int p, int curans) {

    bool subfaka = subcount(u) == 0;
    int up = tr[0].query(1, 1, n, st[u], st[u]);
    bool upfaka = up ? subcount(up) == 1 : 0;

    tr[1].update(1, 1, n, st[u], st[u], 1);
    if (subfaka) {
        if (up == 0 || upfaka) {
            if (up) {
                tr[0].update(1, 1, n, st[up], en[up], -up);
//                cout<<st[up]<<" "<<en[up]<<" "<<-up<<endl;
            }
        }
        if (up == 0 || !upfaka) curans++;
        tr[0].update(1, 1, n, st[u], en[u], u);
//        cout<<st[u]<<" "<<en[u]<<" "<<u<<endl;
    }

    ans = max(ans, curans);
//    cout<<"Add "<<u<<" --> "<<curans<<" "<<subfaka<<" "<<up<<" "<<upfaka<<endl;

    for (int v: adj[0][u]) {
        if (v == p) continue;
        dfs2(v, u, curans);
    }

    tr[1].update(1, 1, n, st[u], st[u], -1);
    if (subfaka) {
        if (up == 0 || upfaka) {
            curans++;
            if (up) tr[0].update(1, 1, n, st[up], en[up], up);
        }
        tr[0].update(1, 1, n, st[u], en[u], -u);
    }

}

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

    int t;
    cin>>t;

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

        for (int i=1; i<=n; i++)    adj[0][i].clear(), adj[1][i].clear();

        for (int i=2; i<=n; i++) {
            int x;
            cin>>x;
            adj[0][x].push_back(i);
            adj[0][i].push_back(x);
        }

        for (int i=2; i<=n; i++) {
            int x;
            cin>>x;
            adj[1][x].push_back(i);
            adj[1][i].push_back(x);
        }

        clk = 0;
        dfs1(1, 0);

//        for (int i=1; i<=n; i++)    cout<<i<<" "<<st[i]<<" "<<en[i]<<endl;

        tr[0].build(1, 1, n);
        tr[1].build(1, 1, n);

        ans = 0;
        dfs2(1, 0, 0);
        cout<<ans<<"\n";
    }
}