#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e, p) for (ll i = (ll)s; i < (ll)e; i += p)
#define ALL(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;

    ll l = pow(10, 9), s = -pow(10, 9), a, t, m = 0;
    rep(i, 0, n, 1){
        cin >> a >> t;
        if (t == 1){
            m += a;
            s += a;
            l += a;
        }else if (t == 2){
            if (l < a) l = a;
            s = max(a, s);
        }else{
            if (a < s) s = a;
            l = min(l, a);
        }
    }

    ll q, x;
    cin >> q;
    rep (i, 0, q, 1){
        cin >> x;
        if (x + m <= s) cout << s << endl;
        else if (l <= x + m) cout << l << endl;
        else cout << x + m << endl;
    }

    return 0;
}

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);

	int n,q;
	cin>>n;
	ll l=-1e18,r=1e18,p=0;
	for(int i=0;i<n;i++){
		ll a,t;
		cin>>a>>t;
		if(t==1)l+=a,r+=a,p+=a;
		if(t==2)chmax(r,a),chmax(l,a);
		if(t==3)chmin(l,a),chmin(r,a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		ll x;
		cin>>x;
		x += p;
		chmax(x,l);
		chmin(x,r);
		cout << x << "\n";
	}
}