#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
#define x first
#define y second
#define mp make_pair

const int MAXN = (int)2e5;
int n, q;
ll a[MAXN + 5], t[MAXN + 5], x[MAXN + 5], sol[2 * MAXN + 5];
vector <int> ms[2 * MAXN + 5];
set <pll> s;

void dfs(int x, int p){
	for(vector <int>::iterator i = ms[x].begin() ; i != ms[x].end() ; ++i){
		int o = *i;
		if(o == p)
			continue;
		sol[o] = sol[x];
		dfs(o, x);
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i){
	cin >> a[i] >> t[i];
}
cin >> q;
for(int i = 1 ; i <= q ; ++i){
	cin >> x[i];
	s.insert(mp(x[i], i));
}
ll sad = 0;
for(int i = 1 ; i <= n ; ++i){
	if(t[i] == 1){
		sad += a[i];
	}
	else if(t[i] == 2){
		while(!s.empty() && (s.begin())->x <= a[i] - sad){
			int o = s.begin()->y;
			s.erase(s.begin());
			ms[i + q].push_back(o);
		}
		s.insert(mp(a[i] - sad, i + q));
	}
	else{
		while(!s.empty() && (--s.end())->x >= a[i] - sad){
			int o = (--s.end())->y;
			s.erase((--s.end()));
			ms[i + q].push_back(o);
		}
		s.insert(mp(a[i] - sad, i + q));
	}
}
for(set <pll>::iterator i = s.begin() ; i != s.end() ; ++i){
	pll o = *i;
	sol[o.y] = o.x + sad;
	dfs(o.y, -1);
}
for(int i = 1 ; i <= q ; ++i){
	cout << sol[i] << "\n";
}

return 0;
}


#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, ll>;
#define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)
const int MOD = 1000000007;
const int MOD2 = 998244353;
const ll INF = 1e18;
const ld PI = acos(-1);

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<ll> siz;
    vector<int> isequal;
    UnionFind(int N): par(N), rnk(N), siz(N), isequal(N){
        for(int i = 0; i < N; i++){
            par[i] = i, rnk[i] = 0, siz[i] = 1;
        }
    }
    //根
    int find(int x){
        if(par[x] ==x )return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
            siz[rx] = 0;
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            siz[ry] = 0;
            if(rnk[rx] == rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    //集合が同じか
    bool same(int x, int y){
        return find(x) == find(y);
    }
    //集合の大きさ
    ll size(int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin >> N;
    vector<ll> A(N),T(N);
    ll delta=0;
    rep(i,0,N-1){
        cin >> A[i] >> T[i];
        if(T[i]==1) delta+=A[i];
    }
    cin >> Q;
    vector<int> X(Q);
    rep(i,0,Q-1){
        cin >> X[i];
    }
    ll mx=INF,mn=-INF;
    rep(i,0,N-1){
        if(T[i]==1){
            mx+=A[i];
            mn+=A[i];
        }
        else if(T[i]==2){
            mx=max(A[i],mx);
            mn=max(A[i],mn);
        }
        else if(T[i]==3){
            mx=min(A[i],mx);
            mn=min(A[i],mn);
        }
    }
    /*cout << delta << endl;
    cout << mx << ' ' << mn << endl;*/
    rep(i,0,Q-1){
        if(X[i]+delta>=mx){
            cout << mx << endl;
        }
        else if(X[i]+delta<=mn){
            cout << mn << endl;
        }
        else{
            cout << X[i]+delta << endl;
        }
    }
}