#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

#ifdef LOCAL
#define log(val) std::cerr << std::setw(3) << __LINE__ << "| " << #val << " = " << (val) << std::endl
#define dbg(proc) proc
#else
#define log(val) 0
#define dbg(proc) 0
#endif

template <typename T>
std::ostream& operator<<(std::ostream& os,const std::vector<T>& v){os << "{";if(!v.empty()){os << v[0];for(std::size_t i=1;i<v.size();++i){os << ", " << v[i];}}return os << "}";}

using ll = std::int64_t;
using P = std::tuple<ll,int>;

int N, Q;
int a[200100], t[200100];
P p[200100];
ll res[200100];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> a[i] >> t[i];
    }

    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int x;
        std::cin >> x;

        p[i] = std::make_tuple(x, i);
    }

    std::sort(p, p + Q);

    // [0, l) 内はすべて同じ値 vl を取る
    // (r, N-1] 内はすべて同じ値 vr を取る
    // [l, r] には一様に acc が加えられている
    int l = 0, r = Q - 1;
    constexpr ll INF = 1001001001;
    ll vl = -INF, vr = INF, acc = 0;

    for(int i=0;i<N;++i){
        if(t[i] == 1){
            vl += a[i];
            acc += a[i];
            vr += a[i];
        }else if(t[i] == 2){
            while(l < Q && fst(p[l]) + acc <= a[i]){
                l += 1;
            }
            
            vl = std::max<ll>(vl, a[i]);
            vr = std::max<ll>(vr, a[i]);
        }else{
            while(r >= 0 && fst(p[r]) + acc >= a[i]){
                r -= 1;
            }

            vl = std::min<ll>(vl, a[i]);
            vr = std::min<ll>(vr, a[i]);
        }
    }

    for(int i=0;i<l;++i){
        res[snd(p[i])] = vl;
    }

    for(int i=l;i<=r;++i){
        res[snd(p[i])] = fst(p[i]) + acc;
    }

    for(int i=r+1;i<Q;++i){
        res[snd(p[i])] = vr;
    }

    for(int i=0;i<Q;++i){
        std::cout << res[i] << std::endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=20000010;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll>a(n),t(n);
    rep(i,n)cin>>a[i]>>t[i];
    ll su=inf,ma=inf;
    ll de=-inf,mi=-inf;
    ll now=0;
    rep(i,n){
        if(t[i]==1){
            now+=a[i];
            ma+=a[i];
            mi+=a[i];
        }
        if(t[i]==2){
            if(mi>a[i])continue;
            if(ma<=a[i]){
                de=inf;
                su=-inf;
                ma=a[i],mi=a[i];
                continue;
            }
            de=a[i]-now;
            mi=a[i];
        }
        if(t[i]==3){
            if(ma<a[i])continue;
            if(mi>=a[i]){
                de=inf;
                su=-inf;
                ma=a[i],mi=a[i];
                continue;
            }
            su=a[i]-now;
            ma=a[i];
        }
        //cout<<de<<' '<<su<<' '<<mi<<' '<<ma<<endl;
    }
    ll q;cin>>q;
    rep(i,q){
        ll x;cin>>x;
        if(su<=de){
            cout<<ma<<endl;
        }else{
            if(x>=su){
                cout<<ma<<endl;
            }else if(x<=de){
                cout<<mi<<endl;
            }else{
                cout<<x+now<<endl;
            }
        }
    }
}