from collections import Counter



N = int(eval(input()))

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



ctr = Counter()

ans = 0

for Si in S:

    x = "".join(sorted(list(Si)))

    if x in ctr:

        ans += ctr[x]

    ctr[x] += 1



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

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



cnt = {}

ans = 0



for Si in S:

    x = "".join(sorted(list(Si)))

    if x not in cnt:

        cnt[x] = 0

    ans += cnt[x]

    cnt[x] += 1



print(ans)
from collections import Counter

N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
ctr = Counter()
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x in ctr:
        ans += ctr[x]
    ctr[x] += 1
print(ans)

N = int(eval(input()))
S = [eval(input()) for _ in range(N)]
cnt = {}
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x not in cnt:
        cnt[x] = 0
    ans += cnt[x]
    cnt[x] += 1
print(ans)

-from collections import Counter - -ctr = Counter() +cnt = {} -    if x in ctr: -        ans += ctr[x] -    ctr[x] += 1 +    if x not in cnt: +        cnt[x] = 0 +    ans += cnt[x] +    cnt[x] += 1