eval(input())

a, b, c = set(), set(), set()

for x in eval(input()):

  c |= {y + x for y in b}

  b |= {y + x for y in a}

  a.add(x)

print((len(c)))

eval(input())

a, b, c = set(), set(), set()

for x in eval(input()):

  c.update(y + x for y in b)

  b.update(y + x for y in a)

  a.add(x)

print((len(c)))

eval(input())
a, b, c = set(), set(), set()
for x in eval(input()):
    c |= {y + x for y in b}
    b |= {y + x for y in a}
    a.add(x)
print((len(c)))

eval(input())
a, b, c = set(), set(), set()
for x in eval(input()):
    c.update(y + x for y in b)
    b.update(y + x for y in a)
    a.add(x)
print((len(c)))

-    c |= {y + x for y in b} -    b |= {y + x for y in a} +    c.update(y + x for y in b) +    b.update(y + x for y in a)