N = int(eval(input()))

lst = [eval(input()) for _ in range(N)]

lst = [sorted(i) for i in lst]

lst = ["".join(i) for i in lst]



cnt = 0

dic = {}



for i in lst:

    if i in dic:

        cnt += dic[i]

        dic[i] += 1

    else:

        dic[i] = 1



print(cnt)
N = int(eval(input()))

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

S = ["".join(sorted(s)) for s in S]



cnt = 0

dic = {}



for w in S:

    if w in dic:

        cnt += dic[w]

        dic[w] += 1

    else:

        dic[w] = 1

        

print(cnt)
N = int(eval(input()))
lst = [eval(input()) for _ in range(N)]
lst = [sorted(i) for i in lst]
lst = ["".join(i) for i in lst]
cnt = 0
dic = {}
for i in lst:
    if i in dic:
        cnt += dic[i]
        dic[i] += 1
    else:
        dic[i] = 1
print(cnt)

N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
S = ["".join(sorted(s)) for s in S]
cnt = 0
dic = {}
for w in S:
    if w in dic:
        cnt += dic[w]
        dic[w] += 1
    else:
        dic[w] = 1
print(cnt)

-lst = [eval(input()) for _ in range(N)] -lst = [sorted(i) for i in lst] -lst = ["".join(i) for i in lst] +S = [eval(input()) for _ in range(N)] +S = ["".join(sorted(s)) for s in S] -for i in lst: -    if i in dic: -        cnt += dic[i] -        dic[i] += 1 +for w in S: +    if w in dic: +        cnt += dic[w] +        dic[w] += 1 -        dic[i] = 1 +        dic[w] = 1