N = int(eval(input()))

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



ans = 0

for i,a in enumerate(A):

  if i == A[a] and i < a:

    ans += 1

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

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

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

N = int(eval(input()))
A = [int(i) - 1 for i in input().split()]
print((len([1 for i, a in enumerate(A) if i == A[a] and i < a])))

-ans = 0 -for i, a in enumerate(A): -    if i == A[a] and i < a: -        ans += 1 -print(ans) +print((len([1 for i, a in enumerate(A) if i == A[a] and i < a])))