# Arup Guha
# 4/29/2025
# Solution to 2025 COP 4516 Team Final Contest Problem: Dan the Delivery Man

# Process cases.
nC = int(input())
for loop in range(nC):

    # Get nodes and number of deliveries.
    toks = input().split()
    n = int(toks[0])
    k = int(toks[1])

    # Make 1-based parent list.
    par = [0,1]
    toks = input().split()
    for i in range(n-1):
        par.append(int(toks[i]))

    # Mark used edges.
    used = []
    for i in range(n+1):
        used.append(False)

    # Get deliveries.
    deliveries = [int(x) for x in input().split()]

    # Do each.
    for x in deliveries:

        # Mark each edge up ancestral path.
        cur = x
        while cur != 1:
            used[cur] = True
            cur = par[cur]

    # Count number of used edges.
    cnt = 0
    for i in range(2, n+1):
        if used[i]:
            cnt += 1

    # Ta da!
    print(cnt)
    
