#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
// constexpr int INF = 1070000000;
// constexpr long long LINF = 4611686015206162431;
// constexpr long long MOD = 1000000007;
// constexpr long double PI = 3.1415926535897932;
 

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;
    vc<ll> a(N), t(N);
    rep (i, N) cin >> a[i] >> t[i];
    
    ll r = 1e+16, l = -1e+16;
    ll sum = 0;
    rep (i, N) {
        if (t[i] == 1) {
            l += a[i];
            r += a[i];
            sum += a[i];
        }
        else if (t[i] == 2) {
            l = max(l, a[i]);
            if (r < l) r = l;
        }
        else {
            r = min(r, a[i]);
            if (r < l) l = r;
        }
    }
    
    int Q;
    cin >> Q;
    rep (i, Q) {
        ll x;
        cin >> x;
        x += sum;
        if (x > r) cout << r << endl;
        else if (x < l) cout << l << endl;
        else cout << x << endl;
    }
}
#include<bits/stdc++.h>
using namespace std;
int N;
long long a;
int t;
int Q;
long long x;
long long mi=0x3f3f3f3f3f3f3f3f;
long long ma=0xcfcfcfcfcfcfcfcf;
long long add;
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        scanf("%lld %d",&a,&t);
        if(t==2)
        {
            ma=max(ma,a);
            mi=max(mi,a);
            continue;
        }
        if(t==3)
        {
            ma=min(ma,a);
            mi=min(mi,a);
            continue;
        }
        mi+=a;
        ma+=a;
        add+=a;
    }
    scanf("%d",&Q);
    while(Q--)
    {
        scanf("%lld",&x);
        printf("%lld ",max(min(mi,x+add),ma));
    }
    printf("\n");
    return 0;
}
