#include<iostream>
using namespace std;
typedef long long li;
#define LIM 2000000000000000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li my_plus(li a,li t){
  if(a==LIM or a==-LIM) return a;
  return a+t;
}

struct f{
  li a,b,c;
  f(li aa=0,li bb=LIM,li cc=-LIM){a=aa; b=bb; c=cc;};
  f& add(li p,int t){
    if(t==1){
      a+=p;
      b=my_plus(b,p);
      c=my_plus(c,p);
    }
    if(t==2){
      c=max(c,p);
    }
    if(t==3){
      b=min(b,p);
      c=min(c,p);
    }
    return *this;
  }
  li sayo(li x){
    return max(min(x+a,b),c);
  }
};

int main(){
  int n; cin >>n;
  f fun;
  rep(i,n){
    li a,t; cin >>a >>t;
    fun.add(a,t);
  }
  int q; cin >>q;
  rep(i,q){
    li x; cin >>x;
    print(fun.sayo(x));
  }
}

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

int main() {
	long long n,i,q,x,lx,ly,rx,ry,d,ans;
	cin >> n;
	vector<long long> a(n),t(n);
	for(i=0; i<n; i++){
		cin >> a[i] >> t[i];
	}
	lx=-1000000000000000000; ly=-1000000000000000000;
	rx=1000000000000000000; ry=1000000000000000000;
	for(i=0; i<n; i++){
		if(t[i]==1){
			ly+=a[i]; ry+=a[i];
		}else if(t[i]==2){
			if(ry<=a[i]){
				lx=rx;
				ly=a[i];
				ry=a[i];
			}else if(ly<=a[i]){
				d=a[i]-ly;
				lx+=d;
				ly+=d;
			}
		}else if(t[i]==3){
			if(ly>=a[i]){
				rx=lx;
				ly=a[i];
				ry=a[i];
			}else if(ry>=a[i]){
				d=ry-a[i];
				rx-=d;
				ry-=d;
			}
		}
	}
	cin >> q;
	while(q--){
		cin >> x;
		if(x<=lx){
			ans=ly;
		}else if(x>=rx){
			ans=ry;
		}else{
			ans=(x-lx)+ly;
		}
		cout << ans << endl;
	}

	return 0;
}