include[HTML_REMOVED]
using namespace std;
typedef long long LL;
const int N = 105;
int a[N][N];
int main()
{
int r, y, g,n;
cin >> r >> y >> g;
cin >> n;
for (int i = 0; i < n; i)
cin >> a[i][0]>>a[i][1];
int ans = 0;
for(int i=0;i<n;i)
{
if (a[i][0] == 0)
ans += a[i][1];
else if (a[i][0] == 1)
ans += a[i][1];
else if (a[i][0] == 2)
ans = ans + r + a[i][1];
else if (a[i][0] == 3)
ans = ans;
}
cout << ans << endl;
return 0;
}