#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int r,y,g;
int n;
int main()
{
cin>>r>>y>>g;
cin>>n;
int ans = 0;
while(n--)
{
int k,t;
cin>>k>>t;
if(k==1) ans+=t;
else if(k==2) ans+=t+r;
else if(k==0) ans+=t;
}
cout<<ans;
return 0;
}