#include<bits/stdc++.h> using namespace std; int main(){ int red,yellow,green,N,a,b,ans=0; cin>>red>>yellow>>green>>N; while(~scanf("%d%d",&a,&b)) if(a==0||a==1) ans+=b; else if(a==2) ans+=b+red; cout<<ans<<endl; return 0; }