import numpy as np

n =int(eval(input()))

strl = [list(eval(input())) for i in range(n)]



count =0

pt = {}

for i in range(n):

    sal = strl[i]

    sal.sort()

    temp = "".join(sal)

    if temp in list(pt.keys()):

        tempc = pt[temp]

        count +=tempc

        pt[temp]= tempc+1

    else:

        pt[temp]= 1

print(count)
n = int(eval(input()))

s = [eval(input())for  _ in range(n)]

cnt = {}

for x in s:

    p = list(x)

    p.sort()

    b = "".join(p)

    if "".join(p) not in cnt:cnt[b] = 1

    else:cnt[b] +=1

ans = 0

for key in cnt:

    v = cnt[key]

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

print(ans)

    

 

    





import numpy as np

n = int(eval(input()))
strl = [list(eval(input())) for i in range(n)]
count = 0
pt = {}
for i in range(n):
    sal = strl[i]
    sal.sort()
    temp = "".join(sal)
    if temp in list(pt.keys()):
        tempc = pt[temp]
        count += tempc
        pt[temp] = tempc + 1
    else:
        pt[temp] = 1
print(count)

n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
cnt = {}
for x in s:
    p = list(x)
    p.sort()
    b = "".join(p)
    if "".join(p) not in cnt:
        cnt[b] = 1
    else:
        cnt[b] += 1
ans = 0
for key in cnt:
    v = cnt[key]
    ans += v * (v - 1) // 2
print(ans)

-import numpy as np - -strl = [list(eval(input())) for i in range(n)] -count = 0 -pt = {} -for i in range(n): -    sal = strl[i] -    sal.sort() -    temp = "".join(sal) -    if temp in list(pt.keys()): -        tempc = pt[temp] -        count += tempc -        pt[temp] = tempc + 1 +s = [eval(input()) for _ in range(n)] +cnt = {} +for x in s: +    p = list(x) +    p.sort() +    b = "".join(p) +    if "".join(p) not in cnt: +        cnt[b] = 1 -        pt[temp] = 1 -print(count) +        cnt[b] += 1 +ans = 0 +for key in cnt: +    v = cnt[key] +    ans += v * (v - 1) // 2 +print(ans)