#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll N; cin >> N;
    vector<ll> a(N), t(N);
    rep(i,N) cin >> a[i] >> t[i];
    ll l = -inf, r = inf, add = 0;
    ll L = -inf, R = inf;
    bool is_straight = false;
    rep(i,N) {
        if (t[i]==1) {
            if (is_straight) {
                L += a[i];
                R += a[i];
                continue;
            }
            add += a[i];
            if (l!=-inf) L += a[i];
            if (r!=inf) R += a[i];
        } else if (t[i]==2) {
            if (is_straight) {
                chmax(L,a[i]);
                chmax(R,a[i]);
                continue;
            }
            if (a[i]<=L) continue;
            if (R<=a[i]) {
                L = a[i];
                R = a[i];
                is_straight = true;
                continue;
            }
            L = a[i];
            l = L - add;
        } else {
            if (is_straight) {
                chmin(L,a[i]);
                chmin(R,a[i]);
                continue;
            }
            if (R<=a[i]) continue;
            if (a[i]<=L) {
                L = a[i];
                R = a[i];
                is_straight = true;
                continue;
            }
            R = a[i];
            r = R - add;
        }
    }

    ll Q; cin >> Q;
    vector<ll> res(Q);
    rep(q,Q) {
        ll x; cin >> x;
        if (is_straight) {
            res[q] = L;
        } else {
            if (x<=l) res[q] = L;
            else if (x<r) res[q] = x + add;
            else res[q] = R;
        }
    }
    for (ll ans : res) cout << ans << endl;
}
#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;
}
