//201812-1
#include <bits/stdc++.h>
using namespace std;
int main(){
//灯的工作时间顺序
//红绿黄
int r, y, g;scanf("%d%d%d", &r, &y, &g);
int n;scanf("%d", &n);
int totalTime=0;
while (n--){
int k,t;scanf("%d%d", &k, &t);if(k==0)
totalTime+=t;
else if(k==1)
totalTime+=t;
else if(k==2)
totalTime+=t+r;}printf("%d", totalTime);
return 0;}
//201812-2
#include <bits/stdc++.h>
using namespace std;
int main(){
long long light[3], N, k, t, totalTime = 0;
//变化顺序红绿黄
//红 黄 绿
scanf("%lld%lld%lld%lld", &light[0], &light[2], &light[1], &N);
long long sum = light[0] + light[1] + light[2]; //sum为红绿灯变换一周的总时长
while (N--){scanf("%lld%lld", &k, &t);
if (k == 0) //是道路
totalTime += t; //时长直接递增
//k的表示
//红灯1 黄灯2 绿灯3
else{ //是红绿灯
if (k == 1) //将红绿灯标号变为light数组的下标
k = 0;
else if (k == 3)
k = 1;
t = (light[k] - t + totalTime) % sum; //该红绿灯变换的最后一周的时长
while (t > light[k]){ //若t比当前红绿灯时长长
t -= light[k]; //减去当前的红绿灯时长
k = (k + 1) % 3; //转向下一个红绿灯
}
if (k == 0) //是红灯
totalTime += light[k] - t; //加上红灯剩余时长
else if (k == 2) //是黄灯
totalTime += light[k] - t + light[0]; //加上黄灯剩余时长以及红灯时长
}}printf("%lld", totalTime);
return 0;}
//201812-2
#include <bits/stdc++.h>
using namespace std;
int main(){//灯的变化顺序
//红绿黄
int light[3] ={0};scanf("%d%d%d", &light[0], &light[2], &light[1]);
int n;scanf("%d", &n);
int totalTime = light[0] + light[1] + light[2];
long long use = 0;
while (n--){
long long k, t;scanf("%lld%lld", &k, &t);
if (k == 0)
use += t;
else{if (k == 1){
k = 0;}else if (k == 3){
k = 1;}
long long time = (light[k] - t + use)%totalTime;
while (time > light[k]){
time -= light[k];
k = (k + 1) % 3;}
if (k == 0)
use += light[k] - time;
else if (k == 2)
use += light[k] - time + light[0];}}printf("%lld\n", use);
return 0;}
//201812-2
#include <bits/stdc++.h>
using namespace std;
int main(){
// 红绿灯工作顺序->红->绿->黄
vector<int> v(3);scanf("%d%d%d", &v[0], &v[2], &v[1]);
int n;scanf("%d", &n);
long long res = 0;
long long totalTime = v[0] + v[1] + v[2];//红绿灯循环一次使用的时间
long long useTime = 0;//当前小明使用的总时间
int idx;//红绿灯索引
int state;//当前红绿灯的状态
while (n--){
int k, t;scanf("%d%d", &k, &t);
if (k == 0){
res += t;
useTime += t;
continue;} else if (k == 1)
// 红灯
idx = 0;
else if (k == 2)
// 黄灯
idx = 2;
else if (k == 3)
// 绿灯
idx = 1;
// 将当前使用的总时间转换为一次红绿灯循环内的时间
long long temp = useTime % totalTime;
// 转换灯
while (temp >= t) temp -= t, t = v[++idx % 3];
t -= temp;
// 获取当前是什么灯
state = idx % 3;
if (state == 0)//红灯
res += t, useTime += t;
else if (state == 2)//黄灯
res += t + v[0], useTime += t + v[0];}printf("%lld\n", res);
return 0;}