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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

void Solve()
{
	ll N;
	cin >> N;
	VL a(N), t(N);
	REP(i, N) cin >> a[i] >> t[i];
	ll Q;
	cin >> Q;
	VL x(Q);
	REP(i, Q) cin >> x[i];

	ll sum = 0;
	ll maxVal = -INF;
	ll minVal = INF;
	REP(i, N) {
		if (t[i] == 1) {
			sum += a[i];
			maxVal += a[i];
			minVal += a[i];
		}
		if (t[i] == 2) {
			maxVal = max(maxVal, a[i]);
			minVal = max(minVal, a[i]);
		}
		if (t[i] == 3) {
			maxVal = min(maxVal, a[i]);
			minVal = min(minVal, a[i]);
		}
	}

	for (auto q : x) {
		ll ans = q + sum;
		ans = max(ans, maxVal);
		ans = min(ans, minVal);
		cout << ans << endl;
	}
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}

#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define ini(x, y) memset(x, y, sizeof(x));
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e9;
const double PI = acos(-1);
ll a[200001], t[200001], x[200001];

int main(void) {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	// freopen("input.txt", "r", stdin);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> t[i];
	}
	int q; cin >> q;
	for (int i = 1; i <= q; i++) cin >> x[i];
	vector<pll> v;
	for (int i = 1; i <= q; i++) {
		v.push_back({ x[i], i });
	}
	sort(all(v));
	ll tmp = 0;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 1) tmp += a[i];
		else {
			a[i] -= tmp;
		}
	}
	ll mx = -1e18;
	ll mi = 1e18;
	bool chk = false;
	ll val;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 1) continue;
		else if (t[i] == 2) {
			if (chk) {
				val = max(val, a[i]);
			}
			else {
				mx = max(mx, a[i]);
				if (mx >= mi) {
					chk = true;
					val = mx;
				}
			}
		}
		else {
			if (chk) {
				val = min(val, a[i]);
			}
			else {
				mi = min(mi, a[i]);
				if (mi <= mx) {
					chk = true;
					val = mi;
				}
			}
		}
	}
	if (chk) {
		for (int i = 1; i <= q; i++) {
			cout << val + tmp<<'\n';
		}
	}
	else {
		for (int i = 1; i <= q; i++) {
			if (mx > x[i]) cout << mx + tmp << '\n';
			else if (mi < x[i]) cout << mi + tmp << '\n';
			else cout << x[i] + tmp << '\n';
		}
	}

}