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:
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#endif
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 
 
#ifdef __GNUC__
#define _packed __attribute__((packed))
#else
#define _packed
#endif
 
long double EPS = 0.000000001;
 
using namespace std;
 
using ll = long long;
 
const ll mod = 998244353;
using ll = long long;
using pp = pair<ll, ll>;
 
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
 
int n;
vector<int> g1[300000];
vector<int> g2[300000];
 
pp a[300000];
pp err[300000];
 
int res = 0;
 
struct Zal {
    void insert(int v) {
        auto it = s.upper_bound(a[v]);
        if (it != s.end() && a[v].second > it->first) {
            return;
        }
        if (it != s.begin()) {
            --it;
            if (it->second > a[v].first) {
                err[v] = *it;
                s.erase(it);
            }
        }
        s.insert(a[v]);
    }
 
    void erase(int v) {
        s.erase(a[v]);
        if (err[v].first != -1) {
        	s.insert(err[v]);
        }
    }
 
    int get() {
        return s.size();
    }
    void clear() {
        s.clear();
        
    }
    set<pp> s;
};
 
int cnt = 0;
Zal zal;
void precalc(int v) {
    a[v].first = cnt;
    ++cnt;
    for (auto el : g2[v]) {
        precalc(el);
    }
    a[v].second = cnt;
    ++cnt;
}
 
void dfs(int v) {
    zal.insert(v);
    bool leaf = true;
    for (auto el : g1[v]) {
        leaf = false;
        dfs(el);
    }
    if (leaf) {
        res = max(res, zal.get());
    }
    zal.erase(v);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("hui.in", "r", stdin);
    //freopen("hui.out", "w", stdin);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        res = 0;
        cnt = 0;
        zal.clear();
        for (int i = 0; i < n; ++i) {
            err[i] = {-1, -1};
        }
        for (int i = 0; i < n; ++i) {
            g1[i].clear();
            g2[i].clear();
        }
        for (int i = 1; i < n; ++i) {
            int cur;
            cin >> cur;
            g1[--cur].push_back(i);
        }
        for (int i = 1; i < n; ++i) {
            int cur;
            cin >> cur;
            g2[--cur].push_back(i);
        }
        precalc(0);
        dfs(0);
        cout << res << endl;
    }
    return 0;
}