#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 2e5 + 5;
const ll infll = (ld)1e18 + 7;

int n, q;

ll l = -infll, r = infll;
ll delta = 0;
// x <= l -> l, x >= r -> r, l < x < r -> x

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, n){
        int a, t; cin >> a >> t;
        if (t == 1){
            delta += a;
        }
        else if (t == 2){
            if (a <= l + delta){
                continue;
            }
            if (a < r + delta){
                l = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
        else{
            if (a >= r + delta){
                continue;
            }
            if (a > l + delta){
                r = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
    }
    cin >> q;
    while (q--){
        int x; cin >> x;
        if (x <= l) cout << l + delta << endl;
        else if (x >= r) cout << r + delta << endl;
        else cout << x + delta << endl;
    }
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main()
{
	fast
	ll n;
	cin>>n;
	ll p=n+1;
	ll k=(-1+sqrt(1+8*p))/2;
	k+=10;
	while(true)
    {
        ll fun=k*(k+1)/2;
        if(fun<=p){break;}
        k--;
    }
    cout<<n-k+1;
}
