N=int(eval(input()))

dictionary={}

count=0

for i in range(N):

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

    if s in dictionary:

        dictionary[s]+=1

        count+=dictionary[s]

    else:

        dictionary[s]=0

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

dictionary={}

count=0

for i in range(N):

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

    if s in dictionary:

        dictionary[s]+=1

        count+=dictionary[s]

    else:

        dictionary[s]=0

print(count)
N = int(eval(input()))
dictionary = {}
count = 0
for i in range(N):
    s = tuple(sorted(eval(input())))
    if s in dictionary:
        dictionary[s] += 1
        count += dictionary[s]
    else:
        dictionary[s] = 0
print(count)

N = int(eval(input()))
dictionary = {}
count = 0
for i in range(N):
    s = "".join(sorted(eval(input())))
    if s in dictionary:
        dictionary[s] += 1
        count += dictionary[s]
    else:
        dictionary[s] = 0
print(count)

-    s = tuple(sorted(eval(input()))) +    s = "".join(sorted(eval(input())))