n = int(eval(input()))

dict = {}

ans = 0



for i in range(n):

    s = str(sorted(eval(input())))

    if s in list(dict.keys()):

        ans += dict[s]

        dict[s] += 1

    else:

        dict[s] = 1

print(ans)

n = int(eval(input()))

dict = {}

ans = 0



for i in range(n):

    s = tuple(sorted(eval(input())))

    if s in list(dict.keys()):

        ans += dict[s]

        dict[s] += 1

    else:

        dict[s] = 1

print(ans)
n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
    s = str(sorted(eval(input())))
    if s in list(dict.keys()):
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)

n = int(eval(input()))
dict = {}
ans = 0
for i in range(n):
    s = tuple(sorted(eval(input())))
    if s in list(dict.keys()):
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)

-    s = str(sorted(eval(input()))) +    s = tuple(sorted(eval(input())))