#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vint = vector<int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (long long i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }
}
template <typename T>
T& chmin(T& val, T val2) {
    return val = min(val, val2);
}
template <typename T>
T& chmax(T& val, T val2) {
    return val = max(val, val2);
}

void solve() {
    int n; In(n);

    ll yh=2e15,yl=-2e15, acm = 0;
    REP(i,n) {
        ll a, t; In(a,t);
        if (t == 1) {
            acm += a;
            yh += a;
            yl += a;
        } else if (t == 2) {
            if (a > yl) {
                yl = a;
                if (yl > yh) yh = yl;
            }
        } else {
            if (a < yh) {
                yh = a;
                if (yl > yh) yl = yh;
            }
        }
    }
    ll xh = yh - acm, xl = yl - acm;
    int q; In(q);
    vll x(q); In(x);
    REP(i,q) {
        if (yl == yh) {
            Out(yl);
        } else if (x[i] <= xl) {
            Out(yl);
        } else if (x[i] >= xh) {
            Out(yh);
        } else {
            Out(x[i]+acm);
        }
    }
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	vector<int> a(n), t(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> t[i];

	vector<long long> pref(n);
	pref[0] = (t[0] == 1) * a[0];
	for (int i = 1; i < n; i++) {
		pref[i] = (t[i] == 1) * a[i] + pref[i - 1];
	}

	vector<int> p(n);
	iota(p.begin(), p.end(), 0);

	set<pair<long long, int>> mx, mn;
	for (int i = n - 1; i >= 0; i--) {
		if (t[i] == 1) {

		} else {
			long long bound = a[i] - pref[i];
			auto it1 = mx.lower_bound(make_pair(bound, 0));
			auto it2 = mn.lower_bound(make_pair(bound + 1, 0));
			it2 = it2 != mn.begin() ? prev(it2) : mn.end();

			int pos1 = it1 != mx.end() ? it1->second : n, pos2 = it2 != mn.end() ? it2->second : n;
			int pos = min(pos1, pos2);

			if (pos != n) {
				p[i] = p[pos];
			}

			if (t[i] == 2) {
				auto ub = mx.lower_bound(make_pair(bound + 1, 0));
				for (auto it = mx.begin(); it != ub;) {
					it = mx.erase(it);
				}
				mx.emplace(bound, i);
			} else {
				auto lb = mn.lower_bound(make_pair(bound, 0));
				for (auto it = lb; it != mn.end();) {
					it = mn.erase(it);
				}
				mn.emplace(bound, i);
			}
		}
	}

	int q;
	cin >> q;

	while (q--) {
		int x;
		cin >> x;

		auto it1 = mx.lower_bound(make_pair(x, 0));
		auto it2 = mn.upper_bound(make_pair(x, 0));
		it2 = it2 != mn.begin() ? prev(it2) : mn.end();

		int pos1 = it1 != mx.end() ? it1->second : n, pos2 = it2 != mn.end() ? it2->second : n;
		int pos = min(pos1, pos2);

		if (pos != n) {
			cout << a[p[pos]] + pref.back() - pref[p[pos]] << '\n';
		} else {
			cout << x + pref.back() << '\n';
		}
	}
	return 0;
}