import functools import operator symbols = [(name, int(coin)) for _ in [0]*5 for name, coin in (input().split(),)] reels = [[input() for _ in [0]*int(input())] for _ in [0]*3] result, total = [0]*5, 0 for i, (name, coin) in enumerate(symbols): result[i] = reels[0].count(name)*5 * reels[1].count(name) * reels[2].count(name) total += result[i] * coin print(total / functools.reduce(operator.mul, (len(r) for r in reels))) print("\n".join(map(str, result)))