import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt(), y = sc.nextInt(), g = sc.nextInt(), n = sc.nextInt();
int res = 0;
while (n-- > 0) {
int k = sc.nextInt(), t = sc.nextInt();
if (k == 0) res += t;
else if (k == 1) res += t;
else if (k == 2) res += t + r;
}
System.out.println(res);
}
}