//ABC_196_E_
//
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,s,n) for(int i=s;i<n;++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n,q;
    cin >> n;
    const ll INF = ll(1)<<60;
    ll l = -INF, r = INF;
    ll s = 0;
    rep(i,n)
    {
        ll a,t;
        cin >> a >> t;
        if(t == 1)
        {
            l += a;
            r += a;
            s += a;
        }
        else if(t ==2)
        {
            l = max(l,a);
            r = max(r,a);
        }
        else
        {
            l = min(l,a);
            r = min(r,a);
        }
    }
    cin >> q;
    rep(i,q)
    {
        ll x;
        cin >> x;
        x += s;
        ll ans = x;
        if(x <= l) ans = l;
        else if(r <= x) ans = r;
        printf("%ld\n",ans);
    }

    return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define cap(i) ((i-1)%500+1)
#define cp(i) ((i-1)/500+1)
#define uint unsigned int
#define ull unsigned ll
#define ll long long
#define reg register
#define HgS 1000000007
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define len 200000
#define siz 500
il ll rd()
{
    reg ll res=0,lab=1;
    reg char ch=gc();
    while((ch<'0'||ch>'9')&&ch!=EOF)
    {if(ch=='-')lab=-lab;ch=gc();}
    while(ch>='0'&&ch<='9')
        res=(res<<3)+(res<<1)+(ch&15),ch=gc();
    return res*lab;
}
il void prt(ll x,char t='\n')
{
    char ch[70];int tp=0;
    if(!x){fputs("0",stdout);if(t)pc(t);return;}
    if(x<0)pc('-'),x=-x;
    while(x)ch[++tp]=(x%10)^48,x/=10;
    while(tp)pc(ch[tp--]);
    if(t)pc(t);
}
il ll umax(ll a,ll b){return a>b?a:b;}
il ll umin(ll a,ll b){return a<b?a:b;}
ll n,a[len+5],t[len+5],q,x[len+5];
ll mnx=inf,mxx=neinf,add;
int main()
{
    //memset(mnx,0x3f,sizeof(mnx));memset(mxx,0xc0,sizeof(mxx));
    n=rd();for(int i=1;i<=n;++i)a[i]=rd(),t[i]=rd();
    q=rd();
    for(int i=1;i<=q;++i)
        x[i]=rd(),mnx=umin(mnx,x[i]),mxx=umax(mxx,x[i]);
    for(int i=1;i<=n;++i)
    {
        switch(t[i])
        {
            case 1:
            add+=a[i];mnx+=a[i];mxx+=a[i];break;
            case 2:mnx=umax(mnx,a[i]);mxx=umax(mxx,a[i]);break;
            case 3:mnx=umin(mnx,a[i]);mxx=umin(mxx,a[i]);break;
        }
    }
    for(int i=1;i<=q;++i)prt(umin(mxx,umax(mnx,x[i]+add)));
    return 0;
}