N = int(eval(input()))

A = [int(e)-1 for e in input().split()]



ad = [set() for _ in range(N)]



for i, a in enumerate(A):

    ad[a].add(i)



ans = 0



for i, a in enumerate(A):

    if a in ad[i]:

        ans += 1



print((ans//2))
N = int(eval(input()))

A = [int(e)-1 for e in input().split()]



ans = 0



for i, a in enumerate(A):

    if A[a] == i:

        ans += 1



ans //= 2 

print(ans)
N = int(eval(input()))
A = [int(e) - 1 for e in input().split()]
ad = [set() for _ in range(N)]
for i, a in enumerate(A):
    ad[a].add(i)
ans = 0
for i, a in enumerate(A):
    if a in ad[i]:
        ans += 1
print((ans // 2))

N = int(eval(input()))
A = [int(e) - 1 for e in input().split()]
ans = 0
for i, a in enumerate(A):
    if A[a] == i:
        ans += 1
ans //= 2
print(ans)

-ad = [set() for _ in range(N)] -for i, a in enumerate(A): -    ad[a].add(i) -    if a in ad[i]: +    if A[a] == i: -print((ans // 2)) +ans //= 2 +print(ans)