#include<bits/stdc++.h>
using namespace std;
#define int long long //delete if causing problems
#define F first
#define dbg(x)  cout<<#x<<" "<<x<<endl;
#define S second
#define setbit(n) __builtin_popcount(n)
#define all(x) x.begin() , x.end()
#define clr(x) memset(x,0,sizeof(x))
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define endl "\n" //delete if interactive
#define MOD 1000000007
const int inf = 1e18;
int power(int a, int b);


signed   main()
{
	fast
	int tt = 1;
	//cin >> tt;
	while (tt--)
	{
		int n;
		cin >> n;
		int l = -inf, r = inf, add = 0;

		for (int i = 1; i <= n; i++) {
			int ele, type;
			cin >> ele >> type;

			if (type == 1) {
				add += ele;
				l += ele;
				r += ele;
			}
			else if (type == 2) { //max
				l = max(l, ele);
				r = max(r, ele);
			}
			else {
				l = min(l, ele);
				r = min(r, ele);
			}
		}

		int q;
		cin >> q;

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

			int ans = x;
			ans += add;
			if (ans > r) ans = r;
			if (ans < l) ans = l;

			cout << ans << endl;
		}




	}
	return 0;
}

int power(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b % 2) b-- , res = res * a;
		else b = b / 2 , a *= a;
	}
	return res;
}

/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/




#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main() { 
    ll n;
    cin >> n;
    // vector<ll> x, t;
    vector<ll> boarder(2), b(2);
    boarder[0] = INT64_MIN;
    boarder[1] = INT64_MAX;
    // rep(i, 2){
    //     b[i] = boarder[i];
    // }
    boarder[0] += (ll)(3*100000)*(ll)INT32_MAX;
    boarder[1] -= (ll)(3*100000)*(ll)INT32_MAX;
    ll num = 0;
    rep(i, n){
        ll a, t;
        cin >> a >> t;
        if(t==1){
            num += a;
        }
        if(t==2){
            if(boarder[0]+num<a){
                boarder[0] = a-num;
                // b[0] = boarder[0] + num;
            }
            if(boarder[1]+num<a){
                boarder[1] = a-num;
                // boarder[1] = INT64_MAX - (ll)(3*100000)*(ll)INT32_MAX;
                // boarder[0] = boarder[1];
                // b[1] = INT64_MAX - (ll)(2*10000)*(ll)INT32_MAX;
            }
        }
        if(t==3){
            if(a<boarder[0]+num){
                boarder[0] = a-num;
                // boarder[0] = INT64_MIN + (ll)(3*100000)*(ll)INT32_MAX;
                // boarder[1] = boarder[0];
                // b[0] = INT64_MIN + (ll)(2*10000)*(ll)INT32_MAX;
            }
            if(a<boarder[1]+num){
                boarder[1] = a-num;
                // b[1] = INT64_MAX - (ll)(2*10000)*(ll)INT32_MAX;
            }
        }
    }
    int q;
    cin >> q;
    rep(i, q){
        ll x;
        cin >> x;
        if(x<boarder[0]){
            cout << boarder[0] + num << endl;
        }else{
            if(x<boarder[1]){
                cout << x + num << endl;
            }else{
                cout << boarder[1] + num << endl;
            }
        }
    }
    return 0; 
}