from collections import *

d=Counter()

for _ in range(int(eval(input()))): d[input()[0]]+=1

import itertools as it

print((sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3))))
l=[input()[0] for _ in range(int(eval(input())))]

import itertools as it

print((sum(x*y*z for x,y,z in it.combinations([l.count(c) for c in 'MARCH'],3))))
from collections import *

d = Counter()
for _ in range(int(eval(input()))):
    d[input()[0]] += 1
import itertools as it

print((sum(d[s] * d[t] * d[r] for s, t, r in it.combinations("MARCH", 3))))

l = [input()[0] for _ in range(int(eval(input())))]
import itertools as it

print((sum(x * y * z for x, y, z in it.combinations([l.count(c) for c in "MARCH"], 3))))

-from collections import * - -d = Counter() -for _ in range(int(eval(input()))): -    d[input()[0]] += 1 +l = [input()[0] for _ in range(int(eval(input())))] -print((sum(d[s] * d[t] * d[r] for s, t, r in it.combinations("MARCH", 3)))) +print((sum(x * y * z for x, y, z in it.combinations([l.count(c) for c in "MARCH"], 3))))