#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, ll>;
#define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)
const int MOD = 1000000007;
const int MOD2 = 998244353;
const ll INF = 1e18;
const ld PI = acos(-1);

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<ll> siz;
    vector<int> isequal;
    UnionFind(int N): par(N), rnk(N), siz(N), isequal(N){
        for(int i = 0; i < N; i++){
            par[i] = i, rnk[i] = 0, siz[i] = 1;
        }
    }
    //根
    int find(int x){
        if(par[x] ==x )return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
            siz[rx] = 0;
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            siz[ry] = 0;
            if(rnk[rx] == rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    //集合が同じか
    bool same(int x, int y){
        return find(x) == find(y);
    }
    //集合の大きさ
    ll size(int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin >> N;
    vector<ll> A(N),T(N);
    ll delta=0;
    rep(i,0,N-1){
        cin >> A[i] >> T[i];
        if(T[i]==1) delta+=A[i];
    }
    cin >> Q;
    vector<int> X(Q);
    rep(i,0,Q-1){
        cin >> X[i];
    }
    ll mx=INF,mn=-INF;
    rep(i,0,N-1){
        if(T[i]==1){
            mx+=A[i];
            mn+=A[i];
        }
        else if(T[i]==2){
            mx=max(A[i],mx);
            mn=max(A[i],mn);
        }
        else if(T[i]==3){
            mx=min(A[i],mx);
            mn=min(A[i],mn);
        }
    }
    /*cout << delta << endl;
    cout << mx << ' ' << mn << endl;*/
    rep(i,0,Q-1){
        if(X[i]+delta>=mx){
            cout << mx << endl;
        }
        else if(X[i]+delta<=mn){
            cout << mn << endl;
        }
        else{
            cout << X[i]+delta << endl;
        }
    }
}
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return pn * tmp;
}
//constexprあり16桁まで
const int MAX = 10000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 4) {
				C[i * 5 + 3 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 5 + 4] = '\n';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A < 0) {
		A = -A;
		*di++ = '-';
	}
	int dig = 1;
	if (A >= 100000000) {
		if (A >= 1000000000000) {
			if (A >= 1000000000000000) dig = 4;
			else if (A >= 100000000000000) dig = 3;
			else if (A >= 10000000000000) dig = 2;
			memcpy(di + 8 + dig, f.C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + 4 + dig, f.C + A % 10000 * 5, 4);
			A /= 10000;
			memcpy(di + dig, f.C + A % 10000 * 5, 4);
			memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
			di += 13 + dig;
		}
		else {
			if (A >= 100000000000) dig = 4;
			else if (A >= 10000000000) dig = 3;
			else if (A >= 1000000000) dig = 2;
			memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5);
			A /= 10000;
			memcpy(di + dig, f.C + A % 10000 * 5, 4);
			memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
			di += 9 + dig;
		}
	}
	else {
		if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, f.C + A % 10000 * 5, 5);
			memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
			di += 5 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, f.C + A * 5 + 4 - dig, dig + 1);
			di += 1 + dig;
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint();

	ll L = -1e16, R = 1e16;
	ll ima = 0;
	rep(i, N) {
		int a = getint();
		char t = *ci;
		ci += 2;
		if (t == '1') {
			ima += a;
		}
		else if (t == '2') {
			if (L < a - ima) L = a - ima;
			if (R < L) R = L;
		}
		else {
			if (a - ima < R) R = a - ima;
			if (R < L) L = R;
		}
	}

	int Q = getint();
	rep(i, Q) {
		ll tmp = getint();
		if (tmp > R) tmp = R;
		if (tmp < L) tmp = L;
		putint(tmp + ima);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}