//注意红绿灯的循环顺序:红 → 绿 → 黄
//因此碰到黄灯时,还需等待一段红灯时间
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int r,y,g;
int n;
int main(){
scanf("%d%d%d%d",&r,&y,&g,&n);
int res = 0;
while(n--){
int k,t;
scanf("%d%d",&k,&t);
if(k == 0){
res += t;
}else if(k == 1){ //红灯
res += t;
}else if(k == 2){ //黄灯
res += t + r;
}
}
printf("%d",res);
return 0;
}
题目乍一看蛮哈人的