N = 1000001

a = [0]* N

eval(input())

for x in input().split():

  a[int(x)] += 1

for i in range(1, N):

  if a[i]:

    a[i + i::i] = (0 for _ in a[i + i::i])

print((a.count(1)))

N = 1000001

a = [0]* N

_, s = open(0)

for x in s.split():

  a[int(x)] += 1

for i in range(1, N):

  for j in range(i + i, N, i):

    if a[i]:

      a[j] = 0

print((a.count(1)))

N = 1000001
a = [0] * N
eval(input())
for x in input().split():
    a[int(x)] += 1
for i in range(1, N):
    if a[i]:
        a[i + i :: i] = (0 for _ in a[i + i :: i])
print((a.count(1)))

N = 1000001
a = [0] * N
_, s = open(0)
for x in s.split():
    a[int(x)] += 1
for i in range(1, N):
    for j in range(i + i, N, i):
        if a[i]:
            a[j] = 0
print((a.count(1)))

-eval(input()) -for x in input().split(): +_, s = open(0) +for x in s.split(): -    if a[i]: -        a[i + i :: i] = (0 for _ in a[i + i :: i]) +    for j in range(i + i, N, i): +        if a[i]: +            a[j] = 0