n = int(eval(input()))

a = list(map(int,input().split()))

c = 0



for i in range(n):

    if a[i] == -1:

        pass

    elif a[a[i] - 1] - 1 == i:

        c += 1

        a[a[i] - 1] = -1

        a[i] = -1

    else:

        pass



print(c)
n = int(eval(input()))

a = list(map(int,input().split()))

ans = 0

for i in range(n):

    if a[a[i]-1]-1 == i:

        ans += 1

print((ans // 2))
n = int(eval(input()))
a = list(map(int, input().split()))
c = 0
for i in range(n):
    if a[i] == -1:
        pass
    elif a[a[i] - 1] - 1 == i:
        c += 1
        a[a[i] - 1] = -1
        a[i] = -1
    else:
        pass
print(c)

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if a[a[i] - 1] - 1 == i:
        ans += 1
print((ans // 2))

-c = 0 +ans = 0 -    if a[i] == -1: -        pass -    elif a[a[i] - 1] - 1 == i: -        c += 1 -        a[a[i] - 1] = -1 -        a[i] = -1 -    else: -        pass -print(c) +    if a[a[i] - 1] - 1 == i: +        ans += 1 +print((ans // 2))