import sys





def input():

    return sys.stdin.readline()[:-1]





N = int(eval(input()))

s_dic = {}

for _ in range(N):

    s_list = list(eval(input()))

    s_list.sort()

    s = ''.join(s_list)



    if s in s_dic:

        s_dic[s] += 1

    else:

        s_dic[s] = 1



ans = 0

for v in list(s_dic.values()):

    if v >= 2:

        ans += v*(v-1)

print((ans//2))

N = int(eval(input()))



dic = {}

for _ in range(N):

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



    if s in dic:

        dic[s] += 1

    else:

        dic[s] = 1



ans = 0

for v in list(dic.values()):

    if v >= 2:

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

print(ans)

import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(eval(input()))
s_dic = {}
for _ in range(N):
    s_list = list(eval(input()))
    s_list.sort()
    s = "".join(s_list)
    if s in s_dic:
        s_dic[s] += 1
    else:
        s_dic[s] = 1
ans = 0
for v in list(s_dic.values()):
    if v >= 2:
        ans += v * (v - 1)
print((ans // 2))

N = int(eval(input()))
dic = {}
for _ in range(N):
    s = "".join(sorted(eval(input())))
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = 0
for v in list(dic.values()):
    if v >= 2:
        ans += (v * (v - 1)) // 2
print(ans)

-import sys - - -def input(): -    return sys.stdin.readline()[:-1] - - -s_dic = {} +dic = {} -    s_list = list(eval(input())) -    s_list.sort() -    s = "".join(s_list) -    if s in s_dic: -        s_dic[s] += 1 +    s = "".join(sorted(eval(input()))) +    if s in dic: +        dic[s] += 1 -        s_dic[s] = 1 +        dic[s] = 1 -for v in list(s_dic.values()): +for v in list(dic.values()): -        ans += v * (v - 1) -print((ans // 2)) +        ans += (v * (v - 1)) // 2 +print(ans)