#include <bits/stdc++.h>
using namespace std;
long long n,q,a[200005],t[200005],z;
struct name
{
    long long x,i;
}f[200005];

int cmp1(struct name f1,struct name f2)
{return f1.x < f2.x;}

int cmp2(struct name f1,struct name f2)
{return f1.i < f2.i;}

int main ()
{
    scanf ("%lld",&n);
    for (int i = 1;i <= n;++i)
        scanf ("%lld %lld",a+i,t+i);
    scanf ("%lld",&q);
    for (int i = 1;i <= q;++i)
        scanf ("%lld",&f[i].x),f[i].i = i;
    sort(f+1,f+q+1,cmp1);
    for (int i = 1;i <= n;++i)
    {
        if (t[i] == 1) z += a[i];
        else if (t[i] == 2)
            for (int j = 1;j <= q && f[j].x+z < a[i];++j)
                f[j].x = a[i]-z;
        else
            for (int j = q;j >= 1 && f[j].x+z > a[i];--j)
                f[j].x = a[i]-z;
    }
    sort(f+1,f+1+q,cmp2);
    for (int i = 1;i <= q;++i)
        printf ("%lld\n",f[i].x+z);
    return 0;
}
#include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define le(p) ((p)<<1)
#define ri(p) ((p)<<1|1)
#define ll long long
using namespace std;
const ll N=1e6+7;
const ll ninf=-5e18;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
struct que{
	ll x,i;
	que(ll a=0,ll b=0){
		x=a;
		i=b;
	}
	friend bool operator <(que a,que b){
		return a.x<b.x;
	}
};
que s[N];
ll n,q,a[N],t[N],ans[N];
ll L[N],R[N],S[N],Z[N],mx[N],mn[N],add[N];
void up(ll p){
	mx[p]=max(mx[le(p)],mx[ri(p)]);
	mn[p]=min(mn[le(p)],mn[ri(p)]);
}
void down(ll p){
	if(S[p]^ninf){
		S[le(p)]=S[p];
		S[ri(p)]=S[p];
		mx[le(p)]=S[p];
		mn[le(p)]=S[p];
		mx[ri(p)]=S[p];
		mn[ri(p)]=S[p];
		S[p]=ninf;
	}
	if(Z[p]){
		Z[le(p)]=1;
		Z[ri(p)]=1;
		add[le(p)]=0;
		add[ri(p)]=0;
		Z[p]=0;
	}
	mx[le(p)]+=add[p];
	mn[le(p)]+=add[p];
	mx[ri(p)]+=add[p];
	mn[ri(p)]+=add[p];
	add[le(p)]+=add[p];
	add[ri(p)]+=add[p];
	add[p]=0;
}
void build(ll p,ll l,ll r){
	L[p]=l;
	R[p]=r;
	if(l==r){
		S[p]=s[l].x;
		mx[p]=s[l].x;
		mn[p]=s[l].x;
		return;
	}
	ll m=(l+r)>>1;
	build(le(p),l,m);
	build(ri(p),m+1,r);
	S[p]=ninf;
	up(p);
}
void tomin(ll p,ll l,ll r,ll k){
	if(mx[p]<k)
		return;
	if(mn[p]>=k){
		S[p]=k;
		mx[p]=k;
		mn[p]=k;
		add[p]=0;
		Z[p]=1;
		return;
	}
	down(p);
	tomin(le(p),l,r,k);
	tomin(ri(p),l,r,k);
	up(p);
}
void tomax(ll p,ll l,ll r,ll k){
	if(mn[p]>k)
		return;
	if(mx[p]<=k){
		S[p]=k;
		mx[p]=k;
		mn[p]=k;
		add[p]=0;
		Z[p]=1;
		return;
	}
	down(p);
	tomax(le(p),l,r,k);
	tomax(ri(p),l,r,k);
	up(p);
}
ll query(ll p,ll x){
	if(L[p]==R[p])
		return mx[p];
	down(p);
	ll m=(L[p]+R[p])>>1;
	if(x<=m)
		return query(le(p),x);
	return query(ri(p),x);
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	for(ll i=1;i<=n;++i){
		a[i]=read();
		t[i]=read(); 
	}
	q=read();
	for(ll i=1;i<=q;++i)
		s[i]=que(read(),i);
	sort(s+1,s+q+1);
	build(1,1,q);
	for(ll i=1;i<=n;++i){
		switch(t[i]){
			case 1:
				mx[1]+=a[i];
				mn[1]+=a[i];
				add[1]+=a[i];
				break;
			case 2:
				tomax(1,1,n,a[i]);
				break;
			case 3:
				tomin(1,1,n,a[i]);
				break;
		}
	}
	for(ll i=1;i<=q;++i)
		ans[s[i].i]=query(1,i);
	for(ll i=1;i<=q;++i)
		printf("%lld\n",ans[i]);
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}