package ncu.edu.ccf;
import java.util.Scanner;
public class XiaoMingShangXue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int red = sc.nextInt();
int yellow = sc.nextInt();
int green = sc.nextInt();
int n = sc.nextInt();
int[] light = new int[n];
int[] temp = new int[n];
for(int i = 0; i<n; i++) {
light[i] = sc.nextInt();
temp[i] = sc.nextInt();
}
int sum = 0;
for(int i = 0; i<n; i++) {
if(light[i] == 0||light[i] == 1) {
sum = sum + temp[i];
}else if(light[i] == 2) {
sum = sum+temp[i]+red;
}
}
System.out.println(sum);
}
}