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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEB(x)	cout << #x << " " << x << endl;
#define DEB_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

typedef long long int LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VL;

const LL INF = numeric_limits<LL>::max() / 4;

void solve() {
	int n;
	cin >> n;

	LL lo = -INF, hi = INF, add = 0;
	REP(i, n) {
		LL a, t;
		cin >> a >> t;

		if (t == 1) {
			lo += a;
			if (hi < LONG_MAX)
				hi += a;
			add += a;

		} else if (t == 2) {
			CHMAX(lo, a);
			CHMAX(hi, a);

		} else {
			CHMIN(lo, a);
			CHMIN(hi, a);
		}
	}

	int q;
	cin >> q;
	REP(qi, q) {
		LL x;
		cin >> x;
		x += add;
		// cout << clamp(x, lo, hi) << endl;
		cout << (x < lo ? lo : (x > hi ? hi : x)) << endl;
	}
}

int main() {

	IOS
	// int t;
	// cin >> t;

	// while (t--) {
	    solve();
	// }

	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,T;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll Mi=-MAXL,Ma=MAXL;
  {
    rep(i,n) {
      if(a[i].S==1) Mi+=a[i].F;
      if(a[i].S==2) Mi=max(Mi,a[i].F);
      if(a[i].S==3) Mi=min(Mi,a[i].F);
    }
    rep(i,n) {
      if(a[i].S==1) Ma+=a[i].F;
      if(a[i].S==2) Ma=max(Ma,a[i].F);
      if(a[i].S==3) Ma=min(Ma,a[i].F);
    }
  }
  ll l=-MAXL,r=MAXL;
  while(l+1<r) {
    ll m=(l+r)/2;
    ll x=m;
    rep(i,n) {
      if(a[i].S==1) x+=a[i].F;
      if(a[i].S==2) x=max(x,a[i].F);
      if(a[i].S==3) x=min(x,a[i].F);
    }
    if(x<=Mi) l=m;
    else r=m;
  }
  ll z=l;
  R T;
  while(T--) {
    ll x;
    R x;
    if(x<z) pr(Mi);
    else pr(min(Ma,x-z+Mi));
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
