#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 200005;
ll sum[maxn << 2];
ll lzd[maxn << 2];
ll lzc[maxn << 2];
vector<pair<ll,ll>>v;
void pushup(int x) {
    sum[x] = sum[x<<1] + sum[x<<1|1];
}
void pushdown(int x, int l, int r) {
    int mid = (l + r) >> 1;
    if (lzc[x]) {
        lzc[x<<1] = lzc[x<<1|1] = lzc[x];
        lzc[x] = 0;
        lzd[x<<1] = lzd[x<<1|1] = 0;
        sum[x<<1] = (mid - l + 1) * lzc[x<<1];
        sum[x<<1|1] = (r - mid) * lzc[x<<1|1];
    }
    if (lzd[x]) {
        lzd[x<<1] += lzd[x];
        lzd[x<<1|1] += lzd[x];
        sum[x<<1] += lzd[x] * (mid - l + 1);
        sum[x<<1|1] += lzd[x] * (r - mid);
        lzd[x] = 0;
    }
}
void build(int x, int l, int r) {
    if (l == r) {
        sum[x] = v[l].F;
        return;
    }
    int mid = (l + r) >> 1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
    pushup(x);
}
void update(int x, int l, int r, int ql, int qr, ll v) {
    if (ql <= l && qr >= r) {
        lzd[x] += v;
        sum[x] += v * (r - l + 1);
        return;
    }
    int mid = (l + r) >> 1;
    pushdown(x,l,r);
    if (ql <= mid) {
        update(x<<1,l,mid,ql,qr,v);
    }
    if (qr > mid) {
        update(x<<1|1,mid+1,r,ql,qr,v);
    }
    pushup(x);
} 
void update2(int x, int l, int r, int ql, int qr, ll v) {
    if (ql <= l && qr >= r) {
        lzc[x] = v;
        lzd[x] = 0;
        sum[x] = v * (r - l + 1);
        return;
    }
    int mid = (l + r) >> 1;
    pushdown(x,l,r);
    if (ql <= mid) {
        update2(x<<1,l,mid,ql,qr,v);
    }
    if (qr > mid) {
        update2(x<<1|1,mid+1,r,ql,qr,v);
    }
    pushup(x);
} 
ll query(int x, int l, int r, int ql, int qr) {
    if (ql <= l && qr >= r) {
        return sum[x];
    }
    int mid = (l + r) >> 1;
    ll ret = 0;
    pushdown(x,l,r);
    if (ql <= mid) {
        ret += query(x<<1,l,mid,ql,qr);
    }
    if (qr > mid) {
        ret += query(x<<1|1,mid+1,r,ql,qr);
    }
    pushup(x);
    return ret;
}
void solve() {
    int m;
    cin >> m;
    vector<pair<ll,ll>>op;
    f(m) {
        ll a, b;
        cin >> a >> b;
        op.pb({a, b});
    }
    int n;
    cin >> n;
    f1 (n) {
        int a;
        cin >> a;
        v.pb({a, i});
    }
    v.pb({-1e10, -1});
    sort(all(v));
    build(1,1,n);
    for (auto &i : op) {
        if (i.S == 1) {
            update(1,1,n,1, n,i.F);
        }
        else if (i.S == 2) {
            if (query(1,1,n,1,1) >= i.F) {
                continue;
            }
            int l = 1, r = n + 1;
            while (r - l > 1) {
                int mid = (l + r) >> 1;
                if (query(1,1,n,mid,mid) < i.F) {
                     l = mid;
                }
                else {
                    r = mid;
                }
            }
            update2(1,1,n,1,l,i.F);
        }
        else {
            if (query(1,1,n,n,n) <= i.F) {
                continue;
            }
            int l = 0, r = n ;
            while (r - l > 1) {
                int mid = (l + r) >> 1;
                if (query(1,1,n,mid,mid) > i.F) {
                    r = mid;
                }
                else {
                    l = mid;
                }
            }
            update2(1,1,n,r,n,i.F);
        }
    }
    ll ans[n + 5] = {};
    f1(n) {
        ans[v[i].S] = query(1,1,n,i,i);
    }
    f1(n) {
        cout << ans[i] << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}
#include<bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n , a [200005] , t [200005] , q , x [200005] , ans [200005] , ad [200005] , anss [200005];
deque < pair < long long , long long > > dq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin >> n;
    for ( int i = 0 ; i < n ; i ++ ) cin >> a [i] >> t [i];
    cin >> q;
    for ( int i = 0 ; i < q ; i ++ )
    {
        cin >> x [i];
        dq . push_back ( { x [i] , i } );
    }
    sort ( dq . begin () , dq . end () );
    long long sum = 0;
    multiset < pair < long long , long long > > ms;

    for ( int i = 0 ; i < n ; i ++ )
    {
        if ( t [i] == 1 ) sum += a [i];
        if ( t [i] == 2 )
        {
            long long l = a [i];
            while ( ms . size () )
            {
                pair < long long , long long > p = * ms . begin ();
                if ( p . first + sum <= l )
                {
                    ad [ p . second ] = i + 1;
                    ms . erase ( ms . begin () );
                }
                else break;
            }
            ms . insert ( { a [i] - sum , i } );
        }
        if ( t [i] == 3 )
        {
            long long r = a [i];
            while ( ms . size () )
            {
                pair < long long , long long > p = * -- ms . end ();
                if ( r <= p . first + sum )
                {
                    ad [ p . second ] = i + 1;
                    ms . erase ( -- ms . end () );
                }
                else break;
            }
            ms . insert ( { a [i] - sum , i } );
        }
    }

    sum = 0;
    for ( int i = 0 ; i < n ; i ++ )
    {
        if ( dq . size () == 0 ) break;
        if ( t [i] == 1 ) sum += a [i];
        if ( t [i] == 2 )
        {
            long long l = a [i];
            while ( dq [0] . first + sum <= l )
            {
                ans [ dq [0] . second ] = i + 1;
                dq . pop_front ();
                if ( dq . size () == 0 ) break;
            }
        }
        if ( t [i] == 3 )
        {
            long long r = a [i];
            while ( r <= dq [ dq . size () - 1 ] . first + sum )
            {
                ans [ dq [ dq . size () - 1 ] . second ] = i + 1;
                dq . pop_back ();
                if ( dq . size () == 0 ) break;
            }
        }
    }
    sum = 0;
    for ( int i = n - 1 ; i >= 0 ; i -- )
    {
        if ( t [i] == 1 ) sum += a [i];
        if ( ad [i] == 0 ) anss [i] = a [i] + sum;
        else anss [i] = anss [ ad [i] - 1 ];
    }
    for ( int i = 0 ; i < q ; i ++ )
    {
        if ( ans [i] ) cout << anss [ ans [i] - 1 ] << endl;
        else cout << x [i] + sum << endl;
    }
}
