#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int a[200010];
  int t[200010];
  int q;

  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> t[i];
  }

  cin >> q;

  long ub = 1000000000;
  long lb = -ub;
  long offset = 0;
  for (int i = 0; i < n; ++i) {
    if (t[i] == 1) {
      offset += a[i];
      ub += a[i];
      lb += a[i];
    } else if(t[i] == 2) {
      if (lb < a[i]) {
        lb = a[i];
      }
      if (ub < lb) {
        ub = lb;
      }
    } else {
      if (ub > a[i]) {
        ub = a[i];
      }
      if (lb > ub) {
        lb = ub;
      }
    }
  }

  for (int i = 0; i < q; ++i) {
    long x;
    cin >> x;
    x += offset;
    if (x < lb) {
      x = lb;
    }
    if (x > ub) {
      x = ub;
    }
    cout << x << endl;
  }
}

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve(){
    ll N;
    cin >> N;
    vll a(N), t(N);
    rep(i,0,N) cin >> a[i] >> t[i];
    ll Q;
    cin >> Q;
    vll x(Q);
    rep(i,0,Q) cin >> x[i];
    vector<lpair> lp;
    rep(i,0,Q) lp.push_back({x[i], i});
    sort(lp.begin(), lp.end());
    vll ans(Q+1, 0);
    ll min_val = -INF, max_val = INF;
    ll cur = 0;
    rep(i,0,N){
        if(t[i] == 1){
            cur += a[i];
        }else if(t[i] == 2){
            ll val = a[i] - cur;
            min_val = max(min_val, val);
        }else{
            ll val = a[i] - cur;
            max_val = min(max_val, val);
        }
    }
    ll m1 = min_val, m2 = max_val;
    rep(i,0,N){
        if(t[i] == 1){
            m1 += a[i];
            m2 += a[i];
        }else if(t[i] == 2){
            chmax(m1, a[i]);
            chmax(m2, a[i]);
        }else{
            chmin(m1, a[i]);
            chmin(m2, a[i]);
        }
    }
    
    rep(q,0,Q){
        ll X = lp[q].first;
        ll idx = lp[q].second;

        ll res = 0;
        if(X >= min_val && X <= max_val){
            res = m1 + (X - min_val);
        }else if(X < min_val){
            res = m1;
        }else{
            res = m2;
        }
        ans[idx] = res;
    }




    rep(i,0,Q) print(ans[i]);


}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}