#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
ll A[200005];
ll T[200005];

ll func(ll value, ll index) {
    if (T[index] == 1) {
        return value + A[index];
    }
    else if (T[index] == 2) {
        return std::max(value, A[index]);
    }
    return std::min(value, A[index]);
}

ll calc(ll value) {
    REP(i, N) {
        value = func(value, i);
    }
    return value;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        cin >> A[i] >> T[i];
    }

    ll low = calc(-INF);
    ll heigh = calc(INF);
    ll sum = 0;
    REP(i, N) {
        if (T[i] == 1)
            sum += A[i];
    }

    ll Q;
    cin >> Q;
    REP(i, Q) {
        ll x;
        cin >> x;
        if (x < low - sum)
            cout << low << endl;
        else if (heigh - sum < x)
            cout << heigh << endl;
        else
            cout << x + sum << endl;
    }
    return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>
#include <map>
#include <queue>
#include <set>

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector

using namespace std;
using ll = long long int;
using P = pair<int, int>;

int main() {
  int a1, a2, a3;
  int a[3] = {0};
  rep(i, 3) {
    int b;
    cin >> b;
    a[i] = b;
  }

  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) {
      for(int k=0; k<3; k++) {
        if(i!=j && i!=k && j!=k) {
          if(a[k]-a[j] == a[j] - a[i]) {
            say("Yes");
            return 0;
          }
        }
      }
    }
  }
  say("No");

  return 0;
}
