include [HTML_REMOVED]
using namespace std;
int r,y,g;
int div_time(int a,int c)
{
if(a == 1 ||a == 0)
return c;
if(a == 2)
return c+r;
if(a == 3)
return 0;
}
int main()
{
int a[101][2] = {};
cin >> r >> y >> g;
int n;
cin >> n;
int sum = 0;
for(int i = 1;i <= n;i++ )
{
cin >> a[i][0] >> a[i][1];
sum+=div_time(a[i][0],a[i][1]);
}
cout << sum;
return 0;
}