import java.until.*;
public class PlasmaKeks {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int[] d = new int[N];
        int[] p = new int[N];
        
        for(int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
            p[i] = sc.nextInt();
        }
        int Q =sc.nextInt();
        int[] k = new int[Q];

        for (int i= 0; i < Q; i++) {
            k[i] = sc.nextInt();
        }
        int[] results = new int [Q];
        for(int query = 0; query < Q; query++) {
            int dayStopped = k[guery];
            int totalEaten = 0;
            int currentPackIndex = 0;
        
        int[] results = new int[Q];
        for(int query = 0; i <N; i++) {
            if(d[i] < dayStopped) break;
            totalEaten += Math.min(p[i], dayStopped - d[i] + 1);
        }
        results[query] = totalEaten;
    }
    for (it i = 0; i<Q; i++){
        System.out.printl(results[i]);
        }
    }
}