n = int(eval(input()))

d = {}

ans = 0



for i in range(n):

    s = "".join(sorted(eval(input())))

    if s not in d:

        d[s] = 1

    else:

        ans += d[s]

        d[s] += 1

    

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

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

d = {}

ans = 0

for s in S:

    x = "".join(sorted(s))

    if x in d: ans += d[x]

    d[x] = d.get(x,0) + 1

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

n = int(eval(input()))
S = [eval(input()) for _ in range(n)]
d = {}
ans = 0
for s in S:
    x = "".join(sorted(s))
    if x in d:
        ans += d[x]
    d[x] = d.get(x, 0) + 1
print(ans)

+S = [eval(input()) for _ in range(n)] -for i in range(n): -    s = "".join(sorted(eval(input()))) -    if s not in d: -        d[s] = 1 -    else: -        ans += d[s] -        d[s] += 1 +for s in S: +    x = "".join(sorted(s)) +    if x in d: +        ans += d[x] +    d[x] = d.get(x, 0) + 1