_,s=open(0)

x,y,z=eval('set(),'*3)

for c in s[:-1]:

  for t in y:z.add(t+c)

  for t in x:y.add(t+c)

  x.add(c)

print((len(z)))
_,s=open(0)

x,y,z=eval('set(),'*3)

for c in s[:-1]:

  z|={t+c for t in y}

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

  x|={c}

print((len(z)))
_, s = open(0)
x, y, z = eval("set()," * 3)
for c in s[:-1]:
    for t in y:
        z.add(t + c)
    for t in x:
        y.add(t + c)
    x.add(c)
print((len(z)))

_, s = open(0)
x, y, z = eval("set()," * 3)
for c in s[:-1]:
    z |= {t + c for t in y}
    y |= {t + c for t in x}
    x |= {c}
print((len(z)))

-    for t in y: -        z.add(t + c) -    for t in x: -        y.add(t + c) -    x.add(c) +    z |= {t + c for t in y} +    y |= {t + c for t in x} +    x |= {c}