#include<bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N, Q;
int A[200010], T[200010];

int unit(int x)
{
    rep(i, N)
    {
        if(T[i] == 1)x = x + A[i];
        if(T[i] == 2)x = max(x, A[i]);
        if(T[i] == 3)x = min(x, A[i]);
    }
    return x;
}

signed main()
{
    cin >> N;
    rep(i, N)cin >> A[i] >> T[i];

    int LL = -1e15, RR = 1e15;
    LL = unit(LL);
    RR = unit(RR);

    int ll, rr;
    int lv, rv;
    {
        int l = -1e9 - 10, r = 1e9 + 10;
        rep(_, 60)
        {
            int mid = (l + r) / 2;
            int mid_val = mid_val = unit(mid);
            if(LL == mid_val)l = mid;
            else r = mid;
        }
        ll = l;
        lv = unit(ll);

        l = -1e9 - 10, r = 1e9 + 10;
        rep(_, 60)
        {
            int mid = (l + r) / 2;
            int mid_val = unit(mid);
            if(mid_val == RR)r = mid;
            else l = mid;
        }
        rr = r;
        rv = unit(rr);
    }

    cin >> Q;
    rep(i, Q)
    {
        int x;
        cin >> x;
        if(x <= ll)cout << lv << endl;
        else if(rr <= x)cout << rv << endl;
        else cout << lv + (x - ll) << endl;
    }

    return 0;
}
// Bismillahir Rahmanir Rahim
//============================
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define endl        "\n"
#define infL        LLONG_MAX
#define infI        INT_MAX
#define pb          push_back
#define fo(i,a,b)   for(int i=a;i<b;i++)
#define fo2(i,a,b)  for(int i=a;i<=b;i++)
#define rfo(i,a,b)  for(int i=a; i>=b;i--)
#define precise(x,y)cout<<fixed<<setprecision(y)<<x<<endl;
#define MAX         100010
#define yes         cout<<"Yes"<<endl
#define no          cout<<"No"<<endl
#define bye         return 0
#define debug       cout<<"\nDebug\n";
#define debug2      cout<<"\nDebug2\n";
#define PEREGRINE_FALCON {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

typedef pair<ll,ll>PII;
double epsilon = 0.0000001f;
ll mod=1e9+7;
double Pi =acos(-1);

void print(vector<ll>V)
{
      cout<<"\n---------------Vector checking start-------------------\n";
      ll sz=V.size();
      fo(i,0,sz){cout<<V[i]<<"  ";}
      cout<<"\n----------------Vector checking end--------------------\n";
}

void print(ll arr[], ll n)
{
      cout<<"\n---------------Array checking start-------------------\n";
      fo(i,0,n){cout<<arr[i]<<" ";}
      cout<<"\n----------------Array checking end--------------------\n";
}

int main()
{
      PEREGRINE_FALCON
      //freopen("inputNew.txt", "r", stdin);

      ll testCase=1;
      //cin>>testCase;
      while(testCase--){
            ll n,m,k,x,y,z,a,b,c,d,mn,mx,temp,cnt,ans,sum,sz,len;


            ll arr[3];
            fo(i,0,3){cin>>arr[i];}
            sort(arr,arr+3);
            if(arr[2]-arr[1] == arr[1]-arr[0]) yes;
            else no;
      }

      bye;
}
