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 PYTHON3):

Solution:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
    
class FenwickTree:
    def __init__(self, x):
        """transform list into BIT"""
        self.bit = x
        for i in range(len(x)):
            j = i | (i + 1)
            if j < len(x):
                x[j] += x[i]
    def update(self, idx, x):
        """updates bit[idx] += x"""
        while idx < len(self.bit):
            self.bit[idx] += x
            idx |= idx + 1

    def query(self, end):
        """calc sum(bit[:end])"""
        end += 1
        x = 0
        while end:
            x += self.bit[end - 1]
            end &= end - 1
        return x

    def findkth(self, k):
        """Find largest idx such that sum(bit[:idx]) <= k"""
        idx = -1
        for d in reversed(range(len(self.bit).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(self.bit) and k >= self.bit[right_idx]:
                idx = right_idx
                k -= self.bit[idx]
        return idx + 1

g1 = []
g2 = []
st = []
ft = []

def dfs1(graph, start=0):
    n = len(graph)
    tim = 1
    visited = [False] * n    
    stack = [start]
    while stack:
        start = stack[-1]
        if not visited[start]:
            st[start] = tim
            tim = tim + 1
            visited[start] = True
            for child in graph[start]:
                if not visited[child]:
                    stack.append(child)
        else:
            stack.pop()
            ft[start] = tim



def Do(v):
    global ans , cnt , mem
    fen.update(st[v] , 1);
    if(fen.query(ft[v] - 1) - fen.query(st[v])):
        mem += [[v , 0 , 0]]
        return;
    u = fen2.query(st[v]);
    ok[v] = 1
    cnt += 1
    fen2.update(st[v] , v - u)
    fen2.update(ft[v] , u - v)
    mem += [[v , u , ok[u]]]
    cnt -= ok[u]
    ok[u] = 0
    return;



def undo():
    global cnt , ans , mem
    [v , u , a] = mem[-1]
    if(a != 0):
        ok[u] = 1
        cnt += 1
    cnt -= 1
    ok[v] = 0
    fen.update(st[v] , -1)
    fen2.update(st[v] , u - v)
    fen2.update(ft[v] , v - u)
    mem.pop()
    return;


def dfs(graph, start=0):
    global ans , cnt
    n = len(graph)
    visited = [False] * n   
    stack = [start]
    while stack:
        start = stack[-1]
        if not visited[start]:
            Do(start)
            ans = max(ans , cnt)
            visited[start] = True
            for child in graph[start]:
                if not visited[child]:
                    stack.append(child)
        else:
            stack.pop()
            undo()



def solve():
    global n, g1 , g2 , V , st , ft , fen , fen2 , mem , ok , cnt , ans 
    n = int(input())
    if(n == 1):
        print(1)
        exit(0)
    
    g1 = [] ; g2 = []
    
    for i in range(n):
        g1.append([])
        g2.append([])
    
    # 0 base 
    
    V = list(map(int , input().split()))
    
    for i in range ( 1 , n ):
        v = V[i - 1]-1
        g1[v].append(i)
    
    V = list(map(int , input().split()))    
    
    for i in range ( 1 , n ):
        v = V[i-1]-1
        g2[v].append(i)
    st = [0] * (n + 100)
    ft = [0] * (n + 100)
    fen = FenwickTree([0] * (n + 3))
    fen2 = FenwickTree([0] * (n + 3))
    mem = []
    ok = [0]*(n + 100)
    cnt = 0
    ans = 0
    dfs1(g2)
    dfs(g1)
    print(ans)

q = int(input())
for i in range (q):
    solve()