#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122) return char(x-32);
    if( 65 <= int(x) && int(x) <= 90) return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122) return x;
    if( 65 <= int(x) && int(x) <= 90) return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57) return int(x-'0');
    if(97 <= int(x) && int(x) <= 122) return int(x-96);
    if(65 <= int(x) && int(x) <= 90) return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1%MOD;
    else if(num2==1)return num1%MOD;
    else{
        ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template

const int MAXN = 2e5 + 5;
const ll INF = 1e17;
int n;
ll lo, hi, a[MAXN], t[MAXN];

ll f(ll x){
    for(int i = 1; i <= n; ++i) {
        if(t[i] == 1) x += a[i];
        if(t[i] == 2) x = max(x,a[i]);
        if(t[i] == 3) x = min(x,a[i]);
//        watch(x);
    }
    return x;
}

ll binserlo(){
    ll l = -INF, r = INF, res = -1;
    while(l <= r){
        ll mid = (l + r) >> 1LL;
        if(f(mid) <= lo) res = mid, l = mid + 1;
        else r = mid - 1;
    }
    return res;
}

ll binserhi(){
    ll l = -INF, r = INF, res = -1;
    while(l <= r){
        ll mid = (l + r) >> 1LL;
        if(f(mid) >= hi) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    return res;
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i] >> t[i];
    lo = f(-INF), hi = f(INF);
    ll L = binserlo(), R = binserhi();

    int q; cin >> q; while(q--){
        ll x, res; cin >> x;
        if(lo == hi) {cout << lo << newl; continue; }

        if(x < L) res = lo;
        else if(x > R) res = hi;
        else res = lo + (x - L);
        cout << res << newl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e17;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    long long n;
    cin >> n;
    long long f0 = 0, l = -INF, r = INF;
    long long memo = 0;
    for(long long i = 0; i < n; i++){
        long long a, t;
        cin >> a >> t;
        if(t == 1){
            memo += a;
            f0 += a;
            l += a;
            r += a;
        } else if(t == 2){
            f0 = max(f0, (long long)a);
            l = max(l, (long long)a);
            r = max(r, (long long)a);
        } else {
            f0 = min(f0, (long long)a);
            l = min(l, (long long)a);
            r = min(r, (long long)a);
        }

    }


    long long q;
    cin >> q;
    vector<long long> ans(q);
    for(long long i = 0; i < q; i++){
        long long x;
        cin >> x;
        if(l-memo > x) ans[i] = l;
        else if(r-memo < x) ans[i] = r;
        else ans[i] = x+memo;
    }

    for(long long i = 0; i < q; i++) cout << ans[i] << endl;
    return 0;
}