#include<iostream>
#include<vector>
#include<map>
#define MAX 1001
using namespace std;

int M[MAX];
vector< vector<int> > v;

void compute( int depth, int s )
{
	if( depth == v.size() - 1 ){
		for(unsigned int i = 0; i < v[depth].size(); ++i){
			int t = s + v[depth][i];
			if( t < MAX ){
				M[ t ]++;
			}
		}
	}else{
		for(unsigned int i = 0; i < v[depth].size(); ++i){
			compute( depth + 1, s + v[depth][i] ); 
		}
	}
	return ;
}

int main()
{
	while( true ){
		int g, m;
		//vector< vector<int> > v;
		
		v.clear();
		for(int i = 0; i < MAX; ++i){
			M[i] = 0;
		}

		cin >> m;
		if( m == 0 )
			break;
		
		for(int i = 0; i < m; ++i){
			int a, b;
			cin >> a >> b;
			vector<int> vt;
			vt.push_back(0);
			for(int j = 1; j <= b; ++j){
				vt.push_back( a * j );
			}
			v.push_back( vt );
		}

		compute( 0, 0 );

		cin >> g;
		for(int x = 0; x < g; ++x){
			int n;
			cin >> n;

			cout << M[ n ] << endl;
		}
	}
	return 0;
}