import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int red = sc.nextInt();
int yellow = sc.nextInt();
int green = sc.nextInt();
int num = sc.nextInt();
int sum = 0;
for(int i = 0; i < num; i++){
int type = sc.nextInt();
int s = sc.nextInt();
if(type == 0){
sum += s;
}
if(type == 1){
sum += s;
}
if(type == 2){
sum += s+red;
}
}
System.out.print(sum);
}
}