#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, Q; cin >> N;
    vector<int> A(N), T(N);
    REP(i, 0, N) cin >> A[i] >> T[i];

    cin >> Q;
    vector<ll> X(Q);
    REP(i, 0, Q) cin >> X[i]; 


    set<ll> S;
    REP(i, 0, Q) S.insert(X[i]);

    ll offset = 0;
    REP(i, 0, N) {
        if (T[i] == 1) {
            offset += A[i];
        } else if (T[i] == 2) {
            auto itr = S.lower_bound(A[i] - offset);

            bool deleted = false;
            auto jtr = S.begin();
            while (jtr != itr) {
                jtr = S.erase(jtr);
                deleted = true;
            }
            if (deleted) {
                S.insert(A[i] - offset);
            } 
        } else {
            auto itr = S.lower_bound(A[i] - offset);

            bool deleted = false;
            while (itr != S.end()) {
                itr = S.erase(itr);
                deleted = true;
            }
            if (deleted) {
                S.insert(A[i] - offset);
            } 
        }
    }
    // for (auto x : S) cout << x << " ";
    // cout << endl;

    REP(i, 0, Q) {
        auto itr = S.lower_bound(X[i]);
        if (itr != S.begin() && (itr == S.end() || *itr > X[i])) itr = prev(itr);
        // cout << "# i : " << i << ", X[i] : " << X[i] << ", itr : " << *itr << endl;
        cout << *itr + offset << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n], t[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> t[i];
    int q;
    cin >> q;
    int x[q];
    for (int i = 0; i < q; i++) cin >> x[i];
    int lazy = 0;
    int lo = -1e17, hi = 1e17;
    for (int i = 0; i < n; i++) {
        if (t[i] == 1) lazy += a[i];
        else if (t[i] == 2) lo = max(lo, a[i]-lazy);
        else hi = min(hi, a[i]-lazy);
    }
    int loVal = lo;
    int hiVal = hi;
    for (int i = 0; i < n; i++) {
        if (t[i] == 1) {
            loVal += a[i];
            hiVal += a[i];
        }
        if (t[i] == 2) {
            loVal = max(loVal, a[i]);
            hiVal = max(hiVal, a[i]);
        }
        if (t[i] == 3) {
            loVal = min(loVal, a[i]);
            hiVal = min(hiVal, a[i]);
        }
    }
    for (int i = 0; i < q; i++) {
        if (x[i] <= lo) cout << loVal << '\n';
        else if (x[i] >= hi) cout << hiVal << '\n';
        else cout << x[i]+lazy << '\n';
    }
    cout << '\n';
}
/*

*/
