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

int main() {
  int n;
  cin >> n;
  vector<pair<ll, int>> a(n);
  for (auto& e : a) cin >> e.first >> e.second;
  reverse(a.begin(), a.end());

  ll s = 0, bot = -1e18, top = 1e18;
  for (auto e : a) {
    switch (e.second) {
      case 1: {
        s += e.first;
        bot -= e.first;
        top -= e.first;
        break;
      }
      case 2: {
        if (bot == top) break;
        bot = max(bot, e.first);
        bot = min(bot, top);
        break;
      }
      case 3: {
        if (bot == top) break;
        top = min(top, e.first);
        top = max(bot, top);
        break;
      }
    }
  }

  int q;
  cin >> q;
  while (q--) {
    ll x;
    cin >> x;
    cout << max(bot, min(top, x)) + s << endl;
  }
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) per(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

typedef long long ll;

const int MAXN = 2e5 + 10;

int n;
ll add, L = -LONG_LONG_MAX >> 1, R = LONG_LONG_MAX >> 1;

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n);
	REP(i, n) {
		ll v; int t; IO::read(v), IO::read(t);
		if (t == 1) add += v, L += v, R += v;
		else if (t == 2) L = max(L, v), R = max(R, v);
		else R = min(R, v), L = min(L, v);
	}
	int q; IO::read(q);
	REP(i, q) {
		ll x; IO::read(x); x += add;
		IO::write(x <= L ? L : (x >= R ? R : x), '\n');
	}
	return 0;
}
