#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
using namespace std;
int main()
{
int r,y,g;
cin>>r>>y>>g;
int add=r+y+g;
int n;
cin>>n;
long long int ans=0;
// int *a=new int[n];//状态
// int *b=new int [n];//时间
// for(int i=0;i<n;i++)
// {
// cin>>a[i]>>b[i];
// }
int opt,time;
while(n--)
{
cin>>opt>>time;
if(opt==0)
{
ans+=time;
}
else if (opt==1)
{//红
int temp=add-((time+g+add)-ans%add)%add;
//int temp=(ans+y+r-time)%add;
if(temp<=r+y)
{
ans+=r+y-temp;
}
else
{
//绿灯 直行
}
}
else if (opt==2)
{//黄
int temp=add-((time+g+r+add)-ans%add)%add;
//int temp=(ans+y-time)%add;
if(temp<=r+y)
{
ans+=r+y-temp;
}
else
{
//绿灯 直行
}
}
else if (opt==3)
{//绿
int temp=add-((time+add)-ans%add)%add;
//int temp=(ans+add-time)%add;
if(temp<=r+y)
{
ans+=r+y-temp;
}
else
{
//绿灯 直行
}
}
}
cout<<ans<<endl;
return 0;
}