#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int ans[1001];

int fact(int n){
  if(n<2)return 1;
  return fact(n-1)*n;
}

int main(){
  int m;
  while(cin>>m,m){
    memset(ans,0,sizeof(ans));

    rep(i,m){
      int a,b;
      cin>>a>>b;
      for(int j=1000;j>0;j--){
	if(ans[j]==0)continue;
	int u=0;
	for(int k=j+a;k<=1000 && u<b;k+=a){
	  u++;
	  ans[k]+=ans[j];
	}
      }
      rep(j,b)ans[a*j+a]+=1;
    }
    //rep(i,10)cout<<ans[i+1]<<endl;

    int n;
    cin>>n;
    while(n--){
      int a;
      cin>>a;
      cout<<ans[a]<<endl;
    }
  }
}