import collections



n = int(eval(input()))

s = ["".join(sorted(eval(input()))) for _ in range(n)]



c = collections.Counter(s)



ans = 0

for i in set(s):

  x = c[i]

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

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

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

for i in range(n):

  s[i] = ''.join(sorted(s[i]))

t = {}

for i in range(n):

  if s[i] in t:

    t[s[i]] += 1

  else:

    t[s[i]] = 1

print((sum(t[k] * (t[k] -1) // 2 for k in t)))
import collections

n = int(eval(input()))
s = ["".join(sorted(eval(input()))) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for i in set(s):
    x = c[i]
    ans += x * (x - 1) // 2
print(ans)

n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
for i in range(n):
    s[i] = "".join(sorted(s[i]))
t = {}
for i in range(n):
    if s[i] in t:
        t[s[i]] += 1
    else:
        t[s[i]] = 1
print((sum(t[k] * (t[k] - 1) // 2 for k in t)))

-import collections - -s = ["".join(sorted(eval(input()))) for _ in range(n)] -c = collections.Counter(s) -ans = 0 -for i in set(s): -    x = c[i] -    ans += x * (x - 1) // 2 -print(ans) +s = [eval(input()) for _ in range(n)] +for i in range(n): +    s[i] = "".join(sorted(s[i])) +t = {} +for i in range(n): +    if s[i] in t: +        t[s[i]] += 1 +    else: +        t[s[i]] = 1 +print((sum(t[k] * (t[k] - 1) // 2 for k in t)))