include[HTML_REMOVED]
using namespace std;
int main(){
int r,y,g;
int i,j,l=1,k,t,n,s=0;
cin>>r>>y>>g;
cin>>n;
while(n–){
cin>>k>>t;
if(k==0){
s=s+t;
}
else if(k==1){
s=s+t;
}
else if(k==2){
s=s+t+r;
}
}
cout<<s<<endl;
return 0;
}