#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "< P; string egara[5]; int coins[5]; int n[3]; string rrr[3][5252]; int ids[3][5252]; int idscnt[3][5]; int main(){ REP(i,5)cin>>egara[i]>>coins[i]; REP(i,3){ cin>>n[i]; REP(j,n[i])cin>>rrr[i][j]; REP(j,n[i]){ ids[i][j] = -1; REP(k,5)if(rrr[i][j]==egara[k]){ ids[i][j] = k; idscnt[i][k]++; } } } ll ans[5] = {0,0,0,0,0}; REP(i,n[0])REP(j,n[1]){ int lu = i, lm = (i+1)%n[0], ld = (i+2)%n[0]; int ru = j, rm = (j+1)%n[1], rd = (j+2)%n[1]; if(ids[0][lu] == ids[1][ru]){ int k = ids[0][lu]; if(k!=-1)ans[k] += idscnt[2][k]; } if(ids[0][lm] == ids[1][rm]){ int k = ids[0][lm]; if(k!=-1)ans[k] += idscnt[2][k]; } if(ids[0][ld] == ids[1][rd]){ int k = ids[0][ld]; if(k!=-1)ans[k] += idscnt[2][k]; } if(ids[0][lu] == ids[1][rm]){ int k = ids[0][lu]; if(k!=-1)ans[k] += idscnt[2][k]; } if(ids[0][ld] == ids[1][rm]){ int k = ids[0][ld]; if(k!=-1)ans[k] += idscnt[2][k]; } } double aaa = 0.0; REP(i,5)aaa += ans[i] * coins[i]; REP(i,3)aaa /= n[i]; printf("%.9f\n",aaa); REP(i,5)printf("%lld\n",ans[i]); return 0; }