#include <bits/stdc++.h>

using namespace std;

template<typename T>
void debug(vector<T> item) {

	for (auto i : item) {
		cout << i << " ";
	}

	cout << endl;
}

int main() {
	int N;

	cin >> N;

	int64_t mn = -(int64_t)1e9;
	int64_t mx = 1e9;

	int64_t sum = 0;
	for (int i = 0; i < N; ++i) {
		int64_t a, b;
		cin >> a >> b;

		if (b == 1) {
			sum += a;
			mn += a;
			mx += a;
		} else if (b == 2) {
			mn = max(a, mn);
			mx = max(a, mx);
		} else {
			mn = min(a, mn);
			mx = min(a, mx);
		}
	}

	int Q;

	cin >> Q;

	for (int i = 0; i < Q; ++i) {
		int64_t q;
		cin >> q;

		q += sum;

		if (mn <= q && q <= mx) {
			cout << q << endl;
		} else if (q < mn) {
			cout << mn << endl;
		} else {
			cout << mx << endl;
		}
	}


	return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

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


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


	int N;
	cin >> N;

	int A[200000], T[200000], X[200000];
	rep(i, N) {
		cin >> A[i] >> T[i];
	}
	int Q;
	cin >> Q;
	rep(i, Q) cin >> X[i];

	ll L = -1e16, R = 1e16;
	ll ima = 0;
	rep(i, N) {
		if (T[i] == 1) {
			ima += A[i];
		}
		if (T[i] == 2) {
			chmax(L, A[i] - ima);
			chmax(R, L);
		}
		if (T[i] == 3) {
			chmin(R, A[i] - ima);
			chmin(L, R);
		}
	}

	rep(i, Q) {
		ll tmp = X[i];
		chmin(tmp, R);
		chmax(tmp, L);
		co(tmp + ima);
	}

	Would you please return 0;
}