#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, ll>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	ll sum = 0;
	ll low = -INF, high = INF;
	FOR(i,0,N){
		ll a, t;
		cin >> a >> t;
		if(t == 1){
			sum += a;
		}else{
			a -= sum;
			if(t == 2){
				low = max(low, a);
				if(low >= high){
					high = low;
				}
			}else{
				high = min(high, a);
				if(low >= high){
					low = high;
				}
			}
		}
	}

	int Q;
	cin >> Q;
	while(Q--){
		ll num;
		cin >> num;
		if(num < low){
			num = low;
		}
		if(num > high){
			num = high;
		}
		num += sum;
		cout << num << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(v) v.begin( ), v.end()
#define rep(i, n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
#define rrep(i, n) for(int i=(n); i>=0; i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }




int main(){
    int N; cin >> N;
    vector<int> minNum(N+1); minNum[1] = 1;
    rept(i, 1, N+1){
        for(int j=i*2; j<=N; j += i){
            chmax(minNum[j], minNum[i]+1);
        }
    }

    rept(i, 1, N+1)cout << minNum[i] << " ";
    cout << ln;
}
