#yuki662 strs={} for i in range(5): strg,coin=input().split() strs[strg]=int(coin) n1=int(input()) A=[] for i in range(n1): A.append(input()) n2=int(input()) B=[] for i in range(n2): B.append(input()) n3=int(input()) C=[] for i in range(n3): C.append(input()) s={} res=0 for i in strs: s[i]=A.count(i)*B.count(i)*C.count(i)*5 res+=(s[i]/(n1*n2*n3))*strs[i] print(res) for i in s: print(s[i])