d,a={},0

for i in range(int(eval(input()))):

  k=''.join(sorted(eval(input())))

  d[k]=d.get(k,-1)+1

  a+=d[k]

print(a)
c={}

for _ in range(int(eval(input()))):

  s=tuple(sorted(eval(input())))

  c[s]=c.get(s,0)+1

print((sum(v*(v-1)//2 for v in list(c.values())))) 
d, a = {}, 0
for i in range(int(eval(input()))):
    k = "".join(sorted(eval(input())))
    d[k] = d.get(k, -1) + 1
    a += d[k]
print(a)

c = {}
for _ in range(int(eval(input()))):
    s = tuple(sorted(eval(input())))
    c[s] = c.get(s, 0) + 1
print((sum(v * (v - 1) // 2 for v in list(c.values()))))

-d, a = {}, 0 -for i in range(int(eval(input()))): -    k = "".join(sorted(eval(input()))) -    d[k] = d.get(k, -1) + 1 -    a += d[k] -print(a) +c = {} +for _ in range(int(eval(input()))): +    s = tuple(sorted(eval(input()))) +    c[s] = c.get(s, 0) + 1 +print((sum(v * (v - 1) // 2 for v in list(c.values()))))