// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
#define data data1
#define prev prev1
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R)
{
     int val = rng() % R;
     assert(val >= 0);
     return val;
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

void setMod(int mod_val)
{
     MOD = mod_val;
}
//-----------------------------------------------------

void files_init()
{
     //freopen("file.in", "r", stdin);
     //freopen("factorials.txt", "w", stdout);
}

const int N = 2e5+5;
const int LOGN = 20;


int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     cin >> tests;
     rep(ii, 0, tests)
     {
           int n;
           cin>>n;
           vector<int> a(n+1),b(n+1);
           rep(i,2,n+1)
           cin>>a[i];
           rep(i,2,n+1)
           cin>>b[i];

           vector<vector<int>> g1(n+1);
           vector<vector<int>> g2(n+1);
           vector<int> tin(n+1),tout(n+1);
           vector<vector<pair<int,pii>>> updates(n+1);
           //0 or remove
           //1 for insert

           rep(i,2,n+1)
           {
                g1[a[i]].push_back(i);
                g2[b[i]].push_back(i);
           } 

           int timer=0;
           function<void(int)> dfs1=[&](int i)
           {
                 tin[i]=++timer;
                 for(auto it:g2[i])
                 dfs1(it);
                 tout[i]=++timer;
           };

           dfs1(1);

           set<pii> best;

           auto getCandAncestor = [&](int l,int r) -> pii
           {
                 if(best.empty())
                 return {-1,-1};

                 auto it=best.upper_bound({l,-1});
                 if(it==best.begin())
                 return {-1,-1};

                 it--;
                 int l1=it->f,r1=it->s;

                 if(l1<=l && r<=r1)
                 return {l1,r1};

                 return {-1,-1};
           };

           auto hasCandChild = [&](int l,int r) -> bool
           {
                auto it=best.lower_bound({l,-1});
                if(it==best.end())
                return false;

                int l1=it->f,r1=it->s;
                if(l<=l1 && r1<=r)
                return true;

                return false;
           };

           int ans=0;

           function<void(int)> dfs2=[&](int i)
           {
                 int l=tin[i],r=tout[i];
                 
                 if(!hasCandChild(l,r))
                 {
                      pii p=getCandAncestor(l,r);
                      if(p.f!=-1)
                      {
                           best.erase(p);
                           updates[i].push_back({0,p});
                      }
                      best.insert({l,r});
                      updates[i].push_back({1,{l,r}});
                 }

                 ans=max(ans,(int)best.size());

                 for(auto it:g1[i])
                 dfs2(it);

                 for(auto it:updates[i])
                 {
                      if(it.f==0)
                      best.insert(it.s);
                      else
                      best.erase(it.s);
                 }
                 updates[i].clear();
           };

           dfs2(1);
           cout<<ans<<endl;
     }
     return 0;
}
### Prompt

Generate 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
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
#define data data1
#define prev prev1
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R)
{
     int val = rng() % R;
     assert(val >= 0);
     return val;
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

void setMod(int mod_val)
{
     MOD = mod_val;
}
//-----------------------------------------------------

void files_init()
{
     //freopen("file.in", "r", stdin);
     //freopen("factorials.txt", "w", stdout);
}

const int N = 2e5+5;
const int LOGN = 20;


int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     cin >> tests;
     rep(ii, 0, tests)
     {
           int n;
           cin>>n;
           vector<int> a(n+1),b(n+1);
           rep(i,2,n+1)
           cin>>a[i];
           rep(i,2,n+1)
           cin>>b[i];

           vector<vector<int>> g1(n+1);
           vector<vector<int>> g2(n+1);
           vector<int> tin(n+1),tout(n+1);
           vector<vector<pair<int,pii>>> updates(n+1);
           //0 or remove
           //1 for insert

           rep(i,2,n+1)
           {
                g1[a[i]].push_back(i);
                g2[b[i]].push_back(i);
           } 

           int timer=0;
           function<void(int)> dfs1=[&](int i)
           {
                 tin[i]=++timer;
                 for(auto it:g2[i])
                 dfs1(it);
                 tout[i]=++timer;
           };

           dfs1(1);

           set<pii> best;

           auto getCandAncestor = [&](int l,int r) -> pii
           {
                 if(best.empty())
                 return {-1,-1};

                 auto it=best.upper_bound({l,-1});
                 if(it==best.begin())
                 return {-1,-1};

                 it--;
                 int l1=it->f,r1=it->s;

                 if(l1<=l && r<=r1)
                 return {l1,r1};

                 return {-1,-1};
           };

           auto hasCandChild = [&](int l,int r) -> bool
           {
                auto it=best.lower_bound({l,-1});
                if(it==best.end())
                return false;

                int l1=it->f,r1=it->s;
                if(l<=l1 && r1<=r)
                return true;

                return false;
           };

           int ans=0;

           function<void(int)> dfs2=[&](int i)
           {
                 int l=tin[i],r=tout[i];
                 
                 if(!hasCandChild(l,r))
                 {
                      pii p=getCandAncestor(l,r);
                      if(p.f!=-1)
                      {
                           best.erase(p);
                           updates[i].push_back({0,p});
                      }
                      best.insert({l,r});
                      updates[i].push_back({1,{l,r}});
                 }

                 ans=max(ans,(int)best.size());

                 for(auto it:g1[i])
                 dfs2(it);

                 for(auto it:updates[i])
                 {
                      if(it.f==0)
                      best.insert(it.s);
                      else
                      best.erase(it.s);
                 }
                 updates[i].clear();
           };

           dfs2(1);
           cout<<ans<<endl;
     }
     return 0;
}
```