#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a[200010],b[200010],c[200010] = {};
	int n,q;
	cin >> n;
	for(int i = 0;i < n;i++){
		int x,t;
		cin >> x >> t;
		a[i] = -INF;
		b[i] = INF;
		if(t == 1) c[i] = x;
		else if(t == 2) a[i] = x;
		else b[i] = x;

		if(i){
			if(b[i - 1] < a[i] - c[i - 1]) a[i] = b[i] = a[i] - c[i - 1];
			else if(b[i] - c[i - 1] < a[i - 1]) a[i] = b[i] = b[i] - c[i - 1];
			else{
				a[i] = max(a[i] - c[i - 1],a[i - 1]);
				b[i] = min(b[i] - c[i - 1],b[i - 1]);
			}
			c[i] += c[i - 1];
		}
	}
	cin >> q;
	for(int i = 0;i < q;i++){
		int x;
		cin >> x;
		if(x <= a[n - 1]) x = a[n - 1];
		if(x >= b[n - 1]) x = b[n - 1];
		cout << x + c[n - 1] << endl;
	}
}
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;

const int N = 200000 + 10;
const int Q = 200000 + 10; 

struct Item{
	lli val;
	int id;
};

lli ans[Q];
int a[N], t[N];
Item x[Q];

bool cmp(const Item& u, const Item& v){
	return u.val < v.val;
}

int main(){
	lli add, v;
	int n, q, left, right;
	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].val;
		x[i].id = i;
	}
	sort(x + 1, x + q + 1, cmp);
	left = 1, right = q;
	add = 0;
	for (int i=1; i<=n; i++)
		if (t[i] == 1) add += a[i];
		else if (t[i] == 2){
			v = a[i] - add;
			if (x[left].val > v) continue;
			while (left <= right && x[left].val <= v) left ++;
			left --;
			x[left].val = v;
		}
		else{
			v = a[i] - add;
			if (x[right].val < v) continue;
			while (right >= left && x[right].val >= v) right --;
			right ++;
			x[right].val = v;
		}
	for (int i=left; i>=1; i--) x[i].val = x[left].val;
	for (int i=right; i<=q; i++) x[i].val = x[right].val;
	for (int i=1; i<=q; i++) ans[x[i].id] = x[i].val + add;
	for (int i=1; i<=q; i++) cout<<ans[i]<<endl;		
	return 0;
}