n=int(eval(input()))

d={}

for i in range(n):

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

    if s in d:

        d[s]+=1

    else:

        d[s]=1

ans=0

for i in list(d.values()):

    ans+=(i*(i-1))//2

print(ans)

        
n=int(eval(input()))

d={}

for i in range(n):

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

    if s in d:

        d[s]+=1

    else:

        d[s]=1

ans=0

for i in list(d.values()):

    ans+=i*(i-1)//2

print(ans)

        
n = int(eval(input()))
d = {}
for i in range(n):
    s = "".join(sorted(eval(input())))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for i in list(d.values()):
    ans += (i * (i - 1)) // 2
print(ans)

n = int(eval(input()))
d = {}
for i in range(n):
    s = "".join(sorted(eval(input())))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for i in list(d.values()):
    ans += i * (i - 1) // 2
print(ans)

-    ans += (i * (i - 1)) // 2 +    ans += i * (i - 1) // 2