s = {} coin = [0] * 5 for i in range(5): si, coin[i] = input().split() s[si] = i coin[i] = int(coin[i]) n = [0] * 3 u = [5] * 5 for i in range(3): n[i] = int(input()) suit = [0] * 5 for j in range(n[i]): suit[s[input()]] += 1 for j in range(5): u[j] *= suit[j] ans = 0 for i in range(5): ans += u[i] * coin[i] / (n[0] * n[1] * n[2]) print(ans) for i in range(5): print(u[i])