import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main02 {
public static long[] judge(long i,long r,long g,long y) {
long cir=r+g+y;
i=i%cir;
long[] resType=new long[2];
if(i>=0 && i<r) {resType[0]=1; resType[1]=r-i;}
else if(i>=r && i<r+g) {resType[0]=3; resType[1]=r+g-i;}
else {resType[0]=2; resType[1]=cir-i;}
return resType;
}
public static long[] curLight(long k,long t,long r,long g,long y,long past) {
if(k==1) {
past+=r-t;
}
else if(k==3) {
past+=r+g-t;
}
else if(k==2) {
past+=r+g+y-t;
}
return judge(past,r,g,y);
}
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] r1;
try {
r1 = br.readLine().split(" ");
long r=Integer.parseInt(r1[0]);
long y=Integer.parseInt(r1[1]);
long g=Integer.parseInt(r1[2]);
long n=Integer.parseInt(br.readLine());
long sum=0;
for(long i=0;i<n;i++) {
String[] temp=br.readLine().split(" ");
int k=Integer.parseInt(temp[0]);
long t=Integer.parseInt(temp[1]);
if(k==0) sum+=t;
else {
long curK=curLight(k,t,r,g,y,sum)[0];
long curT=curLight(k,t,r,g,y,sum)[1];
if(curK==1) sum+=curT;
else if(curK==2) sum+=curT+r;
}
}
System.out.println(sum);
} catch (IOException e) {
e.printStackTrace();
}
}
}