include [HTML_REMOVED]
using namespace std;
int whichLight(int k,int t,int r){
switch(k){
case 0:return t;
case 1:return t;
case 2:return t+r;
case 3:return 0;
}
}
int main(){
int time=0;
int r,y,g;
cin>>r>>y>>g;
int n;
cin>>n;
int k,t;
for(int i=0;i[HTML_REMOVED]>k>>t;
time=time+whichLight(k,t,r);
}
cout<<time<<endl;
return 0;
}