d,a={},0

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

  k=str(sorted(eval(input())))

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

print(a)
d,a={},0

for s in open(0):k=str(sorted(s));d[k]=d.get(k,-1)+1;a+=d[k]

print(a)
d, a = {}, 0
for i in range(int(eval(input()))):
    k = str(sorted(eval(input())))
    d[k] = d.get(k, -1) + 1
    a += d[k]
print(a)

d, a = {}, 0
for s in open(0):
    k = str(sorted(s))
    d[k] = d.get(k, -1) + 1
    a += d[k]
print(a)

-for i in range(int(eval(input()))): -    k = str(sorted(eval(input()))) +for s in open(0): +    k = str(sorted(s))