n = int(eval(input()))

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

s = sorted(s) + ["a"]



cnt = 1

ans = 0

for i in range(n):

    if s[i] == s[i+1]:

        cnt += 1

    else:

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

        cnt = 1

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

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

for i in range(n):

    s[i] = sorted(s[i])

    s[i] = "".join(s[i])

    

memo = {}



for i in range(n):

    if s[i] not in memo:

        memo[s[i]] = 1

    else:

        memo[s[i]] += 1

ans = 0

for num in memo:

    num = memo[num]

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

print(ans)
n = int(eval(input()))
s = [sorted(eval(input())) for i in range(n)]
s = sorted(s) + ["a"]
cnt = 1
ans = 0
for i in range(n):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        ans += (cnt * (cnt - 1)) // 2
        cnt = 1
print(ans)

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

-s = [sorted(eval(input())) for i in range(n)] -s = sorted(s) + ["a"] -cnt = 1 +s = [eval(input()) for i in range(n)] +for i in range(n): +    s[i] = sorted(s[i]) +    s[i] = "".join(s[i]) +memo = {} +for i in range(n): +    if s[i] not in memo: +        memo[s[i]] = 1 +    else: +        memo[s[i]] += 1 -for i in range(n): -    if s[i] == s[i + 1]: -        cnt += 1 -    else: -        ans += (cnt * (cnt - 1)) // 2 -        cnt = 1 +for num in memo: +    num = memo[num] +    ans += num * (num - 1) // 2