#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> at(n);
  ll pinf = 4e18, minf = -4e18, bias = 0;
  rep(i, n) {
    ll a, t;
    cin >> a >> t;
    if(t == 1) {
      bias += a;
      pinf += a;
      minf += a;
    }
    if(t == 2) {
      pinf = max(pinf, a);
      minf = max(minf, a);
    }
    if(t == 3) {
      pinf = min(pinf, a);
      minf = min(minf, a);
    }
  }
  int q;
  cin >> q;
  while(q--) {
    ll x;
    cin >> x;
    ll ans = min(pinf, max(minf, x+bias));
    cout << ans << endl;
  }
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const ll INF = 1e16;
const int MOD = 1e9+7;
const int MAX_N = 2e5+12;
int N, Q;
ll a[MAX_N],t[MAX_N];
ll x[MAX_N];

void solve()
{
	ll lo = -INF, hi = INF, add = 0;
	for(int i=0;i<N;++i){
		if(t[i]==1){
			add += a[i];
			lo += a[i];
			hi += a[i];
		}else if(t[i]==2){
			lo = max(lo, a[i]);
			hi = max(hi, a[i]);
		}else{
			lo = min(lo, a[i]);
			hi = min(hi, a[i]);
		}
	}
	for(int i=0;i<Q;++i){
		cout<<min(hi,max(lo, x[i]+add))<<'\n';
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> N;
	for(int i=0;i<N;++i)cin>>a[i]>>t[i];
	cin >> Q;
	for(int i=0;i<Q;++i)cin>>x[i];
	solve();
	return 0;
}