#line 1 "/Users/haruki/kyopro/library/template.cpp"
// code by lynmisakura. wish to be accepted!

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define rep(i,N) for(int i = 0;i < N;i++)
#define rng(i,a,b) for(int i = a;i < b;i++)

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

#define mp make_pair
#define pb push_back
#define eb emplace_back

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
    cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
    return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
    cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
    return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
    cout << "{" << p.first << "," << p.second << "}" << '\n';
    return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
    for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
    cin >> p.first >> p.second; return in;
}/////////////////////////////////////////////////////////////////////
///////////////// DON'T TOUCH BEFORE THIS LINE //////////////////////
/////////////////////////////////////////////////////////////////////

#line 2 "combined.cpp"

ll INF = (1LL << 55);
ll low = -INF,high = INF;

ll add = 0;
ll val = 0;
bool fix = false;

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  
  int n;cin >> n;
  rep(i,n){
    ll a;cin >> a;
    int t;cin >> t;
    if(t == 1){
      add += a;
    }else if(t == 2){
      a -= add;
      if(fix){
        val = max(val,a); 
      }else{
        if(a >= high){
          fix = 1;
          val = a;
        }else{
          low = max(low , a);
        }
      }
    }else{
      a -= add;
      if(fix){
        val = min(val,a);
      }else{
        if(a <= low){
          fix = 1;
          val = a;
        }else{
          high = min(high , a);
        }
      }
    }
  } 
  
  low += add;
  high += add;
  int q;cin >> q;
  rep(_,q){
    ll x;cin >> x;
    if(fix){
      cout << val + add << '\n';
    }else{
      x += add;
      if(x <= low){
        cout << low << '\n';
      }else if(x >= high){
        cout << high << '\n';
      }else{
        cout << x << '\n';
      }
    }
  }

}

#include <bits/stdc++.h>
using namespace std;

long long f(vector<long long>& a, vector<long long>& t, const long long& X0){
    long long res = X0;
    for(int i = 1; i < (int)a.size(); ++i){
        if(t[i] == 1){
            res += a[i];
        }else if(t[i] == 2){
            res = max(a[i], res);
        }else{
            res = min(a[i], res);
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    const long long MIN_ELEM = -1e9;
    const long long MAX_ELEM =  1e9;

    long long N;
    cin >> N;

    vector<long long> a(N + 1);
    vector<long long> t(N + 1);
    for(int i = 1; i <= N; ++i){
        cin >> a[i] >> t[i];
    }

    // X0: identity element for 'f(..)'
    // X0 = 0 for '+' operation and X0 = a[1] for 'min' and 'max' operations
    const long long X0 = (t[1] == 1 ? 0 : a[1]);
    long long fInitialValue = f(a, t, X0);
    long long fMinValue = f(a, t, MIN_ELEM);
    long long fMaxValue = f(a, t, MAX_ELEM);

    // Compute left displacement
    long long l = 0;
    long long r = 2 * MAX_ELEM + 5;
    while(l != r){
        long long mid = (l + r) / 2;
        if(f(a, t, X0 - mid) == fInitialValue){
            l = mid + 1;
        }else{
            r = mid;
        }
    }
    long long leftDispl = r - 1;

    // Compute right displacement
    l = 0;
    r = 2 * MAX_ELEM + 5;
    while(l != r){
        long long mid = (l + r) / 2;
        if(f(a, t, X0 + mid) == fInitialValue){
            l = mid + 1;
        }else{
            r = mid;
        }
    }
    long long rightDispl = r - 1;

    // Answer each query
    long long Q;
    cin >> Q;

    vector<long long> x(Q + 1);
    for(int i = 1; i <= Q; ++i){
        cin >> x[i];
    }

    for(int i = 1; i <= Q; ++i){
        long long answer = fInitialValue;
        if(x[i] < X0 && X0 - x[i] >= leftDispl){
            answer = max(fInitialValue - (X0 - x[i]) + leftDispl, fMinValue);
        }else if(x[i] > X0 && x[i] - X0 >= rightDispl){
            answer = min(fInitialValue + (x[i] - X0) - rightDispl, fMaxValue);
        }
        cout << answer << "\n";
    }

    return 0;
}