#include <bits/stdc++.h>
using namespace std ;
int main() {
int a,b,x,y,sum=0;
vector<int> d,v;
while(scanf("%d:%d",&a,&b)==2){
if(a==0&&b==0) break;
d.push_back(a);
v.push_back(b);
}
while(scanf("%d:%d",&x,&y)==2){
if(x==0&&y==0) break;
for(int i=0; i<d.size(); i++) if(x==d[i]) sum+=v[i]*y;
}
printf("%d\n",sum);
}