#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 2e5 + 5;
const ll infll = (ld)1e18 + 7;

int n, q;

ll l = -infll, r = infll;
ll delta = 0;
// x <= l -> l, x >= r -> r, l < x < r -> x

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, n){
        int a, t; cin >> a >> t;
        if (t == 1){
            delta += a;
        }
        else if (t == 2){
            if (a <= l + delta){
                continue;
            }
            if (a < r + delta){
                l = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
        else{
            if (a >= r + delta){
                continue;
            }
            if (a > l + delta){
                r = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
    }
    cin >> q;
    while (q--){
        int x; cin >> x;
        if (x <= l) cout << l + delta << endl;
        else if (x >= r) cout << r + delta << endl;
        else cout << x + delta << endl;
    }
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n, q;
const lli inf = 1e16;
lli a[maxN], t[maxN], x[maxN];

int main()
{
  while (~scanf("%d", &n))
  {
    lli maximumLimit = inf, minimumLimit = -inf, base = 0;
    for (int i = 0; i < n; i++)
      scanf("%lld %lld", &a[i], &t[i]);

    for (int i = 0; i < n; i++)
    {
      if (t[i] == 1)
        base += a[i], maximumLimit += a[i], minimumLimit += a[i];
      else if (t[i] == 2)
        maximumLimit = max(maximumLimit, a[i]), minimumLimit = max(minimumLimit, a[i]);
      else
        maximumLimit = min(maximumLimit, a[i]), minimumLimit = min(minimumLimit, a[i]);
    }

    scanf("%d", &q);

    for (int i = 0; i < q; i++)
      scanf("%lld", &x[i]);

    for (int i = 0; i < q; i++)
    {
      lli ans = max(minimumLimit, min(maximumLimit, x[i] + base));
      printf("%lld\n", ans);
    }
  }
  return 0;
}
