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