role = {} role_list = [] role_hits = {} reel = [] for i in range(5): s = input().split() role[s[0]] = int(s[1]) role_list.append(s[0]) role_hits[s[0]] = 0 for i in range(3): n = int(input()) lst = [] for j in range(n): lst.append(input()) reel.append(lst) n1,n2,n3 = len(reel[0]),len(reel[1]),len(reel[2]) for i in range(n1): x0 = reel[0].pop(0) reel[0].append(x0) for j in range(n2): x1 = reel[1].pop(0) reel[1].append(x1) for k in range(n3): x2 = reel[2].pop(0) reel[2].append(x2) for l in range(3): if reel[0][l]==reel[1][l]==reel[2][l]: role_hits[reel[0][l]] += 1 if reel[0][0]==reel[1][1]==reel[2][2]: role_hits[reel[0][0]] = role_hits.get(reel[0][0],0)+1 if reel[0][2]==reel[1][1]==reel[2][0]: role_hits[reel[0][2]] = role_hits.get(reel[2][0],0)+1 coins = 0 for r,c in role.items(): coins += role_hits[r]*c print(coins/(n1*n2*n3)) for i in role_list: print(role_hits[i])