#include <iostream>
using namespace std;
typedef long long ll;
int main(){
ll r, y, g; cin >> r >> y >> g;
int T; cin >> T;
ll res = 0;
while(T -- ){
int op, t; cin >> op >> t;
if(op == 0) res += t;
if(op == 1) res += t;
else if(op == 2) res += t + r;
}
cout << res << endl;
return 0;
}