n = int(eval(input()))

D = {}

ans = 0

for i in range(n):

    s = str(eval(input()))

    d = [0]*26

    for j in range(len(s)):

        c = ord(s[j])-ord('a')

        d[c] += 1

    d = tuple(d)

    if d in D:

        ans += D[d]

        D[d] += 1

    else:

        D[d] = 1

print(ans)

n = int(eval(input()))

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



d = {}

ans = 0

for i in range(n):

    s = S[i]

    s = list(s)

    s.sort()

    s = ''.join(s)

    if s in d:

        ans += d[s]

    if s in d:

        d[s] += 1

    else:

        d[s] = 1

print(ans)

n = int(eval(input()))
D = {}
ans = 0
for i in range(n):
    s = str(eval(input()))
    d = [0] * 26
    for j in range(len(s)):
        c = ord(s[j]) - ord("a")
        d[c] += 1
    d = tuple(d)
    if d in D:
        ans += D[d]
        D[d] += 1
    else:
        D[d] = 1
print(ans)

n = int(eval(input()))
S = [str(eval(input())) for _ in range(n)]
d = {}
ans = 0
for i in range(n):
    s = S[i]
    s = list(s)
    s.sort()
    s = "".join(s)
    if s in d:
        ans += d[s]
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
print(ans)

-D = {} +S = [str(eval(input())) for _ in range(n)] +d = {} -    s = str(eval(input())) -    d = [0] * 26 -    for j in range(len(s)): -        c = ord(s[j]) - ord("a") -        d[c] += 1 -    d = tuple(d) -    if d in D: -        ans += D[d] -        D[d] += 1 +    s = S[i] +    s = list(s) +    s.sort() +    s = "".join(s) +    if s in d: +        ans += d[s] +    if s in d: +        d[s] += 1 -        D[d] = 1 +        d[s] = 1