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>

using namespace std;
#define rep(i, l, r) for(auto i=(l);i<=(r);++i)
#define per(i, r, l) for(auto i=(r);i>=(l);--i)
#define ll long long
#define N 600030
const int mo = 998244353;
int n, a[N], b[N], in[N], ot[N], id[N], now;
vector<int> e[N];

void dfs1(int x, int fa) {
    in[x] = ++now;
    for (auto v:e[x]) {
        if (v == fa)continue;
        dfs1(v, x);
    }
    id[ot[x] = ++now] = x;
}

int T[2][N << 2];
#define lson k<<1,l,m
#define rson k<<1|1,m+1,r

int ask(int f, int k, int l, int r, int L, int R) {
    if (L > R)return f ? 0 : n + 1;
    if (l >= L && r <= R)return T[f][k];
    int m = l + r >> 1;
    int res = f ? 0 : n + 1;
    if (R > m)res = f ? max(res, ask(f, rson, L, R)) : min(res, ask(f, rson, L, R));
    if (L <= m)res = f ? max(res, ask(f, lson, L, R)) : min(res, ask(f, lson, L, R));
    return res;
}

inline void add(int k, int l, int r, int x, int v) {
    if (l == r) {
        if (v != 0)T[0][k] = T[1][k] = v;
        else T[0][k] = n + 1, T[1][k] = v;
        return;
    }
    int m = l + r >> 1;
    if (x <= m)add(lson, x, v);
    else add(rson, x, v);
    T[0][k] = min(T[0][k << 1], T[0][k << 1 | 1]);
    T[1][k] = max(T[1][k << 1], T[1][k << 1 | 1]);
}

int sz, ans;

void dfs2(int x, int fa) {
    int l = ask(1, 1, 1, n, 1, in[x] - 1);
    int r = ask(0, 1, 1, n, in[x] + 1, n);
    int ad = 0, del = 0;
    if (r == n + 1 || r > ot[x]) {
        if (l != 0 && l >= ot[x]) {
            del = id[l], --sz;
            add(1, 1, n, in[del], 0);
        }
        add(1, 1, n, in[x], ot[x]);
        ad = 1, ++sz;
    }
    ans = max(ans, sz);
    for (auto v:e[x]) {
        if (v == fa)continue;
        dfs2(v, x);
    }
    if (ad)add(1, 1, n, in[x], 0), --sz;
    if (del)add(1, 1, n, in[del], ot[del]), ++sz;
}

void build(int k, int l, int r) {
    T[0][k] = n + 1;
    if (l == r)return;
    int m = l + r >> 1;
    build(lson), build(rson);
}

inline void solve() {
    scanf("%d", &n);
    rep(i, 2, n)scanf("%d", &a[i]);
    rep(i, 2, n)scanf("%d", &b[i]);
    rep(i, 1, n)e[i].clear();
    rep(i, 2, n) {
        e[b[i]].push_back(i);
        e[i].push_back(b[i]);
    }
    now = 0, dfs1(1, 0);
    rep(i, 1, n)e[i].clear();
    rep(i, 2, n) {
        e[a[i]].push_back(i);
        e[i].push_back(a[i]);
    }
    sz = ans = 0, n = now, build(1, 1, n), dfs2(1, 0);
    printf("%d\n", ans);
}

int main() {
    int T = 1;
    scanf("%d", &T);
    while (T--)solve();
}