#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define p_q priority_queue
#define m_p make_pair
#define pb push_back
#define ld long double
#define F first
#define S second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define int ll
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll qpow(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string iots(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int stoi(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
int a[200100];
int t[200100];
int mx,mn;
signed main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>a[i]>>t[i];
	int d=0;
	mx=1e18;mn=-1e18;
	rep(i,n)
	{
		if(t[i]==1)
		{
			d+=a[i];
			mn+=a[i];
			mx+=a[i];
		}
		if(t[i]==2)
		{
			mn=max(mn,a[i]);
			mx=max(mx,a[i]);
		 } 
		if(t[i]==3)
		{
			mn=min(mn,a[i]);
			mx=min(mx,a[i]);
		}
	}
	int q;
	cin>>q;
	rep(i,q)
	{
		int x;
		cin>>x;
		x+=d;
		if(x>mx)x=mx;
		if(x<mn)x=mn;
		cout<<x<<endl;
	}
	return 0;
}
//特判判全
//循环边界
//精度足够
//注意初值

#include <bits/stdc++.h>

using namespace std;

#define maxn 200005
#define ll long long int

ll n, q, x;
ll a, t, low, high, add;

int main(){
	cin >> n;
	low = -1000000000;
	high = 1000000000;
	add = 0;
	for(int i = 0; i < n; i++){
		cin >> a >> t;
		if(t == 1){
			low += a;	
			high += a;
			add += a;
		}else if(t == 2){
			low = max(low, a);
			high = max(high, a);
		}else{
			low = min(low, a);
			high = min(high, a);
		}
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> x;
		//cout << min(high, max(low, x+add)) << "\n";
		cout << max(low, min(high, x+add)) << "\n";
	}
    return 0;
}
