#include<iostream>
using namespace std;
int main(){
int r, y, g;
cin >> r >> y >> g;
int n;
cin >> n;
int tot = 0;
for(int i = 0; i < n; i++){
int k, t;
cin >> k >> t;
if(k == 0){
tot += t;
}else if(k == 1){
tot += t;
}else if(k == 2){
tot += t;
tot += r;
}
}
cout << tot << endl;
return 0;
}