#include <stdio.h>
int main()
{
unsigned int Red,Green,Yellow;
int Count;
int data[100][2];
unsigned Sum = 0;
scanf("%d %d %d",&Red,&Yellow,&Green);
scanf("%d",&Count);
for(int i = 0; i < Count; i++)
{
scanf("%d %d",&data[i][0],&data[i][1]);
}
for(int i = 0; i < Count; i++)
{
switch(data[i][0])
{
case 0:
Sum = Sum + data[i][1];
break;
case 1:
Sum = Sum + data[i][1];
break;
case 2:
Sum = Sum + data[i][1] + Red;
break;
case 3:
break;
default:
break;
}
}
printf("%d",Sum);
return 0;
}