#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dp[100][10000];

int main() {
    int m;
    while (cin >> m && m) {
        int a[m], b[m];
        for (int i = 0; i < m; i++) {
            cin >> a[i] >> b[i];
        }
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 10000; j++) {
                dp[i][j] = 0;
            }
        }
        dp[0][0] = 1;
        for (int i = 0; i < m; i++) {
            for (int k = 0; k <= b[i]; k++) {
                for (int j = 0; j < 10000; j++) {
                    if (j >= k * a[i]) dp[i + 1][j] += dp[i][j - k * a[i]];
                }
            }
        }
        int g;
        cin >> g;
        for (int i = 0, n; i < g; i++) {
            cin >> n;
            cout << dp[m][n] << endl;
        }
    }
}
