n = int(eval(input()))

arr = []

for i in range(n):

    s = list(str(eval(input())))

    s.sort()

    k = ''

    for i in range(10):

        k += s[i]

    arr.append(k)

arr.sort()

ans = 0

count = 1

for i in range(n - 1):

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

        count += 1

        if i == n - 2:

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

    else:

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

        count = 1

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

arr = []

for i in range(n):

    s = list(str(eval(input())))

    s.sort()

    arr.append(s)

arr.sort()

ans = 0

count = 1

for i in range(1, n):

    if arr[i] == arr[i - 1]:

        count += 1

    else:

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

        count = 1

    if i == n - 1:

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

print(ans)
n = int(eval(input()))
arr = []
for i in range(n):
    s = list(str(eval(input())))
    s.sort()
    k = ""
    for i in range(10):
        k += s[i]
    arr.append(k)
arr.sort()
ans = 0
count = 1
for i in range(n - 1):
    if arr[i] == arr[i + 1]:
        count += 1
        if i == n - 2:
            ans += count * (count - 1) // 2
    else:
        ans += count * (count - 1) // 2
        count = 1
print(ans)

n = int(eval(input()))
arr = []
for i in range(n):
    s = list(str(eval(input())))
    s.sort()
    arr.append(s)
arr.sort()
ans = 0
count = 1
for i in range(1, n):
    if arr[i] == arr[i - 1]:
        count += 1
    else:
        ans += count * (count - 1) // 2
        count = 1
    if i == n - 1:
        ans += count * (count - 1) // 2
print(ans)

-    k = "" -    for i in range(10): -        k += s[i] -    arr.append(k) +    arr.append(s) -for i in range(n - 1): -    if arr[i] == arr[i + 1]: +for i in range(1, n): +    if arr[i] == arr[i - 1]: -        if i == n - 2: -            ans += count * (count - 1) // 2 +    if i == n - 1: +        ans += count * (count - 1) // 2