#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}

template <class T>
void chmin(T& a, const T& b) {
  if (b < a) a = b;
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll sum = 0;
  P l = {-INF, 0}, r = {INF, 0};
  bool f = false;
  ll v = 0;
  rep(i, N) {
    ll a, t;
    cin >> a >> t;

    if (t == 1) {
      sum += a;
      l.second += a;
      r.second += a;
    }
    if (t == 2 and l.first < a - sum) {
      if (r.first < a - sum) {
        f = true;
        v = a;
        // r.first = a - sum + 1;
      }
      l.first = a - sum;
      l.second = a;
    }
    if (t == 3 and a - sum < r.first) {
      if (a - sum < l.first) {
        f = true;
        v = a;
        // r.first = a - sum + 1;
      }
      // l.first = a - sum - 1;
      r.first = a - sum;
      r.second = a;
    }

    if (f) {
      if (t == 1) v += a;
      if (t == 2) chmax(v, a);
      if (t == 3) chmin(v, a);
    }
  }

  ll Q;
  cin >> Q;
  rep(i, Q) {
    ll x;
    cin >> x;
    if (f) {
      COUT(v);
      continue;
    }
    if (l.first != -INF and x <= l.first) {
      COUT(l.second);
      continue;
    }
    if (r.first != INF and r.first <= x) {
      COUT(r.second);
      continue;
    }
    COUT(x + sum);
  }

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = (1LL<<60)-1;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)(a.size())

template<class T> 
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}

template<class T> 
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}

ll func(ll y, vector<ll>& a, vector<ll>& t, int n) {
    rep(i, n) {
            if (t[i] == 1)
                y += a[i];
            else if (t[i] == 2) {
                if (y <= a[i]) {
                    y = a[i];
                }
            }
            else if (t[i] == 3) {
                if (y >= a[i]) {
                    y = a[i];
                }
            }
        }
    return y;
}

//コーナーケースに気をつけろ！
int main() {
    int n;  cin >> n;
    vector<ll> a(n), t(n);
    rep(i, n)   cin >> a[i] >> t[i];
    int q;  cin >> q;
    vector<ll> x(q);
    rep(i, q)   cin >> x[i];
    ll l = -INF, r = INF;
    ll b, c;
    ll ok = l, ng = INF;
    while (ok+1 < ng) {
        ll x = (ok + ng) / 2;
        ll y = x;
        bool flag = false;
        rep(i, n) {
            if (t[i] == 1)
                y += a[i];
            else if (t[i] == 2) {
                if (y <= a[i]) {
                    flag = true;
                    y = a[i];
                }
            }
            else if (t[i] == 3) {
                if (y >= a[i]) {
                    y = a[i];
                }
            }
        }
        if (flag)
            ok = x;
        else 
            ng = x;
    }
    l = ok;
    ng = -INF, ok = INF;
    while (ng+1 < ok) {
        ll x = (ok + ng) / 2;
        ll y = x;
        bool flag = false;
        rep(i, n) {
            if (t[i] == 1)
                y += a[i];
            else if (t[i] == 2) {
                if (y <= a[i]) {
                    y = a[i];
                }
            }
            else if (t[i] == 3) {
                if (y >= a[i]) {
                    flag = true;
                    y = a[i];
                }
            }
        }
        if (flag)
            ok = x;
        else 
            ng = x;
    }
    r = ok;
    bool check1 = false, check2 = false, check3 = false;
    ll ans1, ans2, ans3;
    rep(i, q) {
        if (x[i] <= l) {
            if (check1)
                cout << ans1 << endl;
            else {
                check1 = true;
                ans1 = func(x[i], a, t, n);
                cout << ans1 << endl;
            }
        }
        else if (r <= x[i]) {
            if (check3)
                cout << ans3 << endl;
            else {
                check3 = true;
                ans3 = func(x[i], a, t, n);
                cout << ans3 << endl;
            }
        }
        else {
            if (check2)
                cout << x[i] + ans2 << endl;
            else {
                check2 = true;
                ans2 = func(x[i], a, t, n) - x[i];
                cout << x[i] + ans2 << endl;
            }
        }
    }
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;