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;

const int MAXN = 300005;

struct Node {
  pair<int, int> v;
  int t;
  Node *ls, *rs;
  void clear() {
    t = 0;
    v = make_pair(0, 0);
    ls = rs = nullptr;
  }
  void pushUp() {
    if (ls->v.first == rs->v.first) {
      v = make_pair(ls->v.first, ls->v.second + rs->v.second);
    } else {
      v = min(ls->v, rs->v);
    }
  }
  void update(int ft) {
    v.first += ft;
    t += ft;
  }
  void pushDown() {
    if (t) {
      ls->update(t);
      rs->update(t);
      t = 0;
    }
  }
}pool[MAXN<<2];
 
int node_cnt = 0;
 
void clear() {
  node_cnt = 0;
}
 
Node *newNode() {
  pool[node_cnt].clear();
  return &pool[node_cnt++];
}
 
void add(Node *cur, int l, int r, int a, int b, int v) {
  if (a > b) swap(a, b);
  if (a <= l && b >= r) {
    cur->update(v);
  } else {
    cur->pushDown();
    int mid = (l + r) / 2;
    if (a <= mid) {
      add(cur->ls, l, mid, a, b, v);
    }
    if (b > mid) {
      add(cur->rs, mid + 1, r, a, b, v);
    }
    cur->pushUp();
  }
}
 
pair<int, int> query(Node *cur, int l, int r, int a, int b) {
  if (a > b) swap(a, b);
  if (a <= l && b >= r) {
    return cur->v;
  }
  cur->pushDown();
  int mid = (l + r) / 2;
  if (b <= mid) {
    return query(cur->ls, l, mid, a, b);
  }
  if (a > mid) {
    return query(cur->rs, mid + 1, r, a, b);
  }
  pair<int, int> x = query(cur->ls, l, mid, a, b);
  pair<int, int> y = query(cur->rs, mid + 1, r, a, b);
  if (x.first == y.first) {
    return make_pair(x.first, x.second + y.second);
  }
  return min(x, y);
}
 
Node *build(int l, int r) {
  Node *cur = newNode();
  if (l < r) {
    int mid = (l + r) / 2;
    cur->ls = build(l, mid);
    cur->rs = build(mid + 1, r);
    cur->pushUp();
  } else {
    cur->t = 0;
    cur->v = make_pair(0, 1);
  }
  return cur;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    clear();
    int n;
    cin >> n;
    vector<vector<int>> G1(n + 1);
    vector<vector<int>> G2(n + 1);
    for (int i = 2; i <= n; i++) {
      int x;
      cin >> x;
      G1[x].push_back(i);
    }
    for (int i = 2; i <= n; i++) {
      int x;
      cin >> x;
      G2[x].push_back(i);
    }
    vector<int> depth(n + 1);
    vector<int> son(n + 1);
    vector<int> size(n + 1);
    vector<int> father(n + 1);
    function<void(int, int, int)> dfs1 = [&](int cur, int fa, int dep) -> void {
      depth[cur] = dep;
      size[cur] = 1;
      father[cur] = fa;
      for (auto nx: G2[cur]) {
        if (nx == fa) {
          continue;
        }
        dfs1(nx, cur, dep + 1);
        size[cur] += size[nx];
        if (size[nx] > size[son[cur]]) {
          son[cur] = nx;
        }
      }
    };
    vector<int> top(n + 1);
    vector<int> dfn(n + 1);
    vector<int> low(n + 1);
    int dfs_clock = 0;
    function<void(int, int)> dfs2 = [&](int cur, int tp) -> void {
      top[cur] = tp;
      dfn[cur] = ++dfs_clock;
      if (son[cur]) {
        dfs2(son[cur], tp);
      }
      for (auto nx: G2[cur]) {
        if (nx == father[cur] || nx == son[cur]) {
          continue;
        }
        dfs2(nx, nx);
      }
      low[cur] = dfs_clock;
    };
    dfs1(1, 0, 0);
    dfs2(1, 1);
    Node *root = build(1, n);
    auto path_add = [&](int x, int y, int v) -> void {
      int t1 = top[x];
      int t2 = top[y];
      while (t1 != t2) {
        if (depth[t1] < depth[t2]) {
          swap(t1, t2);
          swap(x, y);
        }
        add(root, 1, n, dfn[x], dfn[t1], v);        
        x = father[t1];
        t1 = top[x];
      }
      add(root, 1, n, dfn[x], dfn[y], v);
    };
    auto Q = [&](int x) -> pair<int, int> {
      return query(root, 1, n, dfn[x], dfn[x]);
    };
    const int INF = INT_MAX / 2;
    for (int i = 1; i <= n; i++) {
      path_add(i, i, INF);
    }
    int ans = 0;
    function<void(int)> dfs0 = [&](int cur) -> void {
      auto t = Q(cur);
      assert(t.second == 1);
      path_add(cur, cur, -t.first);
      path_add(1, cur, 1);
      assert(root->v.first >= 1);
      if (root->v.first == 1) {
        ans = max(ans, root->v.second);
      }
      for (auto nx: G1[cur]) {
        dfs0(nx);
      }
      path_add(1, cur, -1);
      path_add(cur, cur, INF);
    };
    dfs0(1);
    cout << ans << "\n";
  }
  return 0;
}