from operator import mul

from functools import reduce



def cmb(n,r):

    r = min(n-r,r)

    if r == 0: return 1

    over = reduce(mul, list(range(n, n - r, -1)))

    under = reduce(mul, list(range(1,r + 1)))

    return over // under

    

    

N = int(eval(input()))

ss = []

for i in range(N):

	ss.append("".join(sorted(list(eval(input())))))

	

dicS = {}

for s in ss:

	if s not in dicS:

		dicS[s] = 1

	else:

		dicS[s] += 1

		

#print(dicS)

		

ans = 0

for v in list(dicS.values()):

	if v != 1:

		ans += cmb(v, 2)

	

print(ans)
N = int(eval(input()))

ss = []

for i in range(N):

	ss.append("".join(sorted(list(eval(input())))))

	

dicS = {}

for s in ss:

	if s not in dicS:

		dicS[s] = 1

	else:

		dicS[s] += 1

		

#print(dicS)

		

ans = 0

for v in list(dicS.values()):

	if v != 1:

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

	

print(ans)
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, list(range(n, n - r, -1)))
    under = reduce(mul, list(range(1, r + 1)))
    return over // under


N = int(eval(input()))
ss = []
for i in range(N):
    ss.append("".join(sorted(list(eval(input())))))
dicS = {}
for s in ss:
    if s not in dicS:
        dicS[s] = 1
    else:
        dicS[s] += 1
# print(dicS)
ans = 0
for v in list(dicS.values()):
    if v != 1:
        ans += cmb(v, 2)
print(ans)

N = int(eval(input()))
ss = []
for i in range(N):
    ss.append("".join(sorted(list(eval(input())))))
dicS = {}
for s in ss:
    if s not in dicS:
        dicS[s] = 1
    else:
        dicS[s] += 1
# print(dicS)
ans = 0
for v in list(dicS.values()):
    if v != 1:
        ans += int((v * (v - 1)) / 2)
print(ans)

-from operator import mul -from functools import reduce - - -def cmb(n, r): -    r = min(n - r, r) -    if r == 0: -        return 1 -    over = reduce(mul, list(range(n, n - r, -1))) -    under = reduce(mul, list(range(1, r + 1))) -    return over // under - - -        ans += cmb(v, 2) +        ans += int((v * (v - 1)) / 2)