#include <bits/stdc++.h>

using namespace std;
const int c=200002;
long long kom[c], a[c], sok=1e16, nagymax=-sok, kismin=sok;
int n, q, t[c];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> a[i] >> t[i];
        kom[i]=kom[i-1];
        if (t[i]==1) {
            kom[i]+=a[i];
        } else {
            a[i]-=kom[i];
            if (t[i]==2) {
                nagymax=max(nagymax, a[i]);
                kismin=max(kismin, nagymax);
            }
            if (t[i]==3) {
                kismin=min(kismin, a[i]);
                nagymax=min(nagymax, kismin);
            }
        }
    }
    cin >> q;
    for (int i=1; i<=q; i++) {
        long long x; cin >> x;
        cout << max(min(x, kismin), nagymax)+kom[n] << "\n";
    }
    return 0;
}

//#define MULTIPLE_TESTS 0
#include "bits/stdc++.h"
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<typename T> using policy_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
struct mul {
    int m;
    mul(int m) : m(m) {}
    int operator()(int a, int b) { return 1ll * a * b % m; }
};
int identity_element(mul) { return 1; }
#define fastpower(a, b, m) power(a,b,mul(m))
#define endl '\n'
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define SZ(v) int((v).size())
const int N = 2e5 + 7, M = 2 * N, MOD = 1e9 + 7, OO = 0x3f3f3f3f;

int n, m, a[N], t[N], x[N], sorted[N];
ll ans[N];
void MAIN(int tc = 0) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        scanf("%d", t + i);
    }
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d", x + i);
    }
    iota(sorted, sorted + m, 0);
    sort(sorted, sorted + m, [](int i, int j) {
        return x[i] < x[j];
    });
    ll plus = 0;
    vector <pair<ll, int>> y;
    for (int i = 0; i < m; ++i) {
        y.emplace_back(x[sorted[i]], 1);
    }
    int st = 0, en = m - 1;
    for (int i = 0; i < n; ++i) {
        if (t[i] == 1) {
            plus += a[i];
        }
        else if (t[i] == 2) {//max
            int j;
            int cnt = 0;
            for (j = st; j <= en && y[j].F+plus < a[i]; ++j) cnt += y[j].S;
            if (cnt)
                y[j - 1] = {a[i]-plus, cnt}, st = j - 1;
        }
        else if (t[i] == 3) {//min
            int j;
            int cnt = 0;
            for (j = en; j >= st && y[j].F+plus > a[i]; --j) cnt += y[j].S;
            if (cnt)
                y[j + 1] = {a[i]-plus, cnt}, en = j + 1;
        }
    }
    int i = 0;
    for(int j = st; j <= en; ++j){
        ll cur = y[j].F;
        int cnt = y[j].S;
        while(cnt--) {
            ans[sorted[i++]] = cur + plus;
        }
    }
    for (int i = 0; i < m; ++i) {
        printf("%lld\n", ans[i]);
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
    freopen("in", "rt", stdin);
#endif
#ifdef MULTIPLE_TESTS
    int nTests;
#if MULTIPLE_TESTS == 0
    scanf("%d", &nTests);
#else
    cin >> nTests;
#endif
    for (int tc = 1; tc <= nTests; ++tc) {
        MAIN(tc);
    }
#else
    MAIN();
#endif

}