N = int(eval(input()))

ss = []

for i in range(N):

    s = list(eval(input()))

    s.sort()

    ss.append(s)



ss.sort()

ans = 0

tmp = 1

for i in range(N-1):

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

        tmp += 1

        if i == N-2:

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

    else:

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

        tmp = 1



print(ans)

N = int(eval(input()))

d = dict()

for i in range(N):

    s = list(eval(input()))

    s.sort()

    s = ''.join(s)

    if s in d:

        d[s] += 1

    else:

        d[s] = 1



ans = 0

for i in list(d.values()):

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



print(ans)
N = int(eval(input()))
ss = []
for i in range(N):
    s = list(eval(input()))
    s.sort()
    ss.append(s)
ss.sort()
ans = 0
tmp = 1
for i in range(N - 1):
    if ss[i] == ss[i + 1]:
        tmp += 1
        if i == N - 2:
            ans += (tmp * (tmp - 1)) // 2
    else:
        ans += (tmp * (tmp - 1)) // 2
        tmp = 1
print(ans)

N = int(eval(input()))
d = dict()
for i in range(N):
    s = list(eval(input()))
    s.sort()
    s = "".join(s)
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for i in list(d.values()):
    ans += (i * (i - 1)) // 2
print(ans)

-ss = [] +d = dict() -    ss.append(s) -ss.sort() +    s = "".join(s) +    if s in d: +        d[s] += 1 +    else: +        d[s] = 1 -tmp = 1 -for i in range(N - 1): -    if ss[i] == ss[i + 1]: -        tmp += 1 -        if i == N - 2: -            ans += (tmp * (tmp - 1)) // 2 -    else: -        ans += (tmp * (tmp - 1)) // 2 -        tmp = 1 +for i in list(d.values()): +    ans += (i * (i - 1)) // 2