#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
	using T = int;
	const T def = 0;
	T f(T a, T b) { return a + b; }
	//==========================================
	vector<int> par;
	vector<T> value;
	UnionFind() {}
	UnionFind(int NV) { init(NV); }
	void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); }
	void reset() { rep(i, 0, par.size()) par[i] = i; }
	int operator[](int x) {
		if (par[x] == x) return x;
		else {
			int res = operator[](par[x]);
			if (res != par[x]) {
				value[res] = f(value[res], value[par[x]]);
				value[par[x]] = def;
			}
			return par[x] = res;
		}
	}
	// uf(x,y)->y
	void operator()(int x, int y) {
		x = operator[](x); y = operator[](y);
		if (x != y) {
			value[y] += value[par[x]];
			value[par[x]] = def;
			par[x] = y;
		}
	}
	T getValues(int x) { return value[operator[](x)]; };
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, A[201010], T[201010];
int Q, X[201010];
deque<pair<ll, int>> que;
//---------------------------------------------------------------------------------------------------
void makeInitialQue() {
	vector<pair<int, int>> v;
	rep(i, 0, Q) v.push_back({ X[i], i });
	sort(all(v));
	fore(p, v) que.push_back({ p.first, p.second });
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i] >> T[i];
	cin >> Q;
	rep(i, 0, Q) cin >> X[i];

	makeInitialQue();

	UnionFind uf(Q);

	ll delta = 0;
	rep(i, 0, N) {
		if (T[i] == 1) delta += A[i];
		else if (T[i] == 2) {
			int top = -1;
			while (!que.empty()) {
				auto p = que.front();
				if (p.first + delta <= A[i]) {
					if (top < 0) top = p.second;
					else uf(top, p.second);
					que.pop_front();
				}
				else break;
			}
			if (0 <= top) que.push_front({ A[i] - delta, uf[top] });
		}
		else if (T[i] == 3) {
			int top = -1;
			while (!que.empty()) {
				auto p = que.back();
				if (A[i] <= p.first + delta) {
					if (top < 0) top = p.second;
					else uf(top, p.second);
					que.pop_back();
				}
				else break;
			}
			if (0 <= top) que.push_back({ A[i] - delta, uf[top] });
		}
	}

	map<int, ll> mp;
	while (!que.empty()) {
		auto p = que.front();
		mp[uf[p.second]] = p.first + delta;
		que.pop_front();
	}

	rep(i, 0, Q) printf("%lld\n", mp[uf[i]]);
}






#include<bits/stdc++.h>
#define int long long
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;



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

    int lo = minf, hi = inf, add = 0;
    int x = inf;
    int n; cin>>n;
    for (int i=1; i<=n; i++) {
        int a,t; cin>>a>>t;
        if (t==1) {
            if (x!=inf) {
                x+=a;
                continue;
            }
            add+=a;
        }
        else if (t==2) {
            if (x!=inf) {
                x=max(x,a);
                continue;
            }
            lo = max(lo, a-add);
            if (lo > hi) x=a;
        }
        else {
            if (x!=inf) {
                x=min(x,a);
                continue;
            }
            hi = min(hi, a-add);
            if (lo > hi) x=a;
        }
    }
    int q; cin>>q;
    while (q--) {
        int a; cin>>a;
        if (x!=inf) cout<<x<<'\n';
        else {
            if (a<lo) a=lo;
            if (a>hi) a=hi;
            cout<<a+add<<'\n';
        }
    }
    return 0;
}