import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import Counter kinds = [] coins = [] for _ in range(5): k,c = readline().split() kinds.append(k) coins.append(int(c)) counter = [] total = 1 for _ in range(3): N = int(readline()) total *= N counter.append(Counter(readline().rstrip() for _ in range(N))) answer = [5 * counter[0][k] * counter[1][k] * counter[2][k] for k in kinds] expected = sum(x * y for x,y in zip(answer, coins)) / total print(expected) print(*answer, sep='\n')