#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<long long>A(N);
	vector<long long>T(N);
	rep(i, N) {
		cin >> A[i] >> T[i];
	}
	long long y0 = -INF - 1;
	long long y1 = INF + 1;
	rep(i, N) {
		if (T[i] == 2) {
			y0 = max(y0, A[i]);
			y1 = max(y1, A[i]);
		}
		else if (T[i] == 1) {
			y0 += A[i];
			y1 += A[i];
		}
		else {
			y0 = min(y0, A[i]);
			y1 = min(y1, A[i]);
		}
	}

	//cout << y0 << endl;
	//cout << y1 << endl;
	long long l = -INF - 1;
	long long r = INF + 1;
	long long tx = 0;
	long long ty = 0;
	if (y0 != y1) {
		while (true) {
			long long c = (l + r) / 2;
			long long copyc = c;
			rep(i, N) {
				if (T[i] == 2) {
					c = max(c, A[i]);
				}
				else if (T[i] == 1) {
					c += A[i];
				}
				else {
					c = min(c, A[i]);
				}
			}
			//cout << copyc << "_" << c << endl;
			if (c == y0) { l = copyc; }
			else if (c == y1) { r = copyc; }
			else {
				tx = copyc;
				ty = c;
				break;
			}
		}
	}
	//cout << tx << "?" << ty << endl;
	long long cl = tx - (ty - y0);
	long long cr = tx + (y1 - ty);
	long long cy = ty - (tx - cl);
	//cout << cl << "_" << cr << "_"<<endl;
	int Q;
	cin >> Q;
	while (Q--) {
		int  x;
		cin >> x;
		if (y0 == y1) {
			cout << y0 << endl;
		}
		else {
			if ((cl <= x) && (x <= cr)) {
				cout << cy + (x - cl) << endl;
			}
			else if (x <= cl) {
				cout << y0 << endl;
			}
			else {
				cout << y1 << endl;
			}
		}
	}
	return 0;
}
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n,q;
ll a[200005];
int t[200005];
P p[200005];
ll ans[200005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%d",&a[i],&t[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		ll x;
		scanf("%lld",&x);
		p[i]=P(x,i);
	}
	sort(p,p+q);
	int l=0,r=q;
	ll lv=p[0].first,rv=p[q-1].first;
	ll dif=0;
	for(int i=0;i<n;i++){
		if(t[i]==1){
			dif+=a[i];
			lv+=a[i];
			rv+=a[i];
		}
		if(t[i]==2){
			rv=max(a[i],rv);
			lv=max(a[i],lv);
			while(l<r && p[l].first+dif<a[i]){
				l++;
			}
		}
		if(t[i]==3){
			rv=min(a[i],rv);
			lv=min(a[i],lv);
			while(l<r && p[r-1].first+dif>a[i]){
				r--;
			}
		}
	}
	//printf("%d %d\n",l,r);
	for(int i=0;i<q;i++){
		if(i<l){
			ans[p[i].second]=lv;
		}else if(l<=i && i<r){
			ans[p[i].second]=p[i].first+dif;
		}else if(r<=i){
			ans[p[i].second]=rv;
		}
	}
	for(int i=0;i<q;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}