N = int(eval(input()))

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



ans = 0

for i in range(N):

  if a[i] != "": n = a[i] - 1

  if a[n] == i + 1:

    ans += 1

    a[n] = ""

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

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



cnt = 0

for i in range(n):

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

    cnt += 1

    a[i] = ""

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

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

-N = int(eval(input())) +n = int(eval(input())) -ans = 0 -for i in range(N): -    if a[i] != "": -        n = a[i] - 1 -    if a[n] == i + 1: -        ans += 1 -        a[n] = "" -print(ans) +cnt = 0 +for i in range(n): +    if a[a[i] - 1] == i + 1: +        cnt += 1 +        a[i] = "" +print(cnt)