#include<bits/stdc++.h> 
using namespace std;                          
#pragma GCC optimize("O3")
typedef long long ll;
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define vec(i, a)  for( auto i=a.begin();i != a.end(); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in  freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sixfive in out 
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
const ll MOD = 1e9 + 7;
ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;}
ll binpow(ll a, ll b, ll m=MOD) 
{
    a%=m;
    ll res=1;
    while (b>0) 
    {
        if (b&1)    res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
int main()
{    
    #ifndef ONLINE_JUDGE
    sixfive
    #endif
    fast
    ll t=1;
    //cin>>t;
    while(t--)
    {    
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
        	cin>>a[i];
        	if(a[i]!=k)
        		cout<<a[i]<<" ";
        }

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<LL> A(N), T(N);
    REP(i, N) {
        cin >> A[i] >> T[i];
    }
    int Q;
    cin >> Q;
    vector<LL> X(Q);
    REP(i, Q) {
        cin >> X[i];
    }

    pair<LL, LL> range(-LINF, LINF);
    LL shift = 0;
    REP(i, N) {
        if(T[i] == 1) {
            shift += A[i];
            range.first += A[i];
            range.second += A[i];
        }
        if(T[i] == 2) {
            if(range.second <= A[i]) {
                range = make_pair(A[i], A[i]);
            }else if(A[i] <= range.first) {
                // 何もしない
            }else{
                range.first = A[i];
            }
        }
        if(T[i] == 3) {
            if(A[i] <= range.first) {
                range = make_pair(A[i], A[i]);
            }else if(range.second <= A[i]) {
                // 何もしない
            }else{
                range.second = A[i];
            }
        }
    }
    REP(i, Q) {
        LL low = range.first;
        LL high = range.second;
        LL r = min<LL>(max<LL>(X[i] + shift, low), high);
        cout << r << endl;
    }
    return 0;
}
