#include<bits/stdc++.h>
using namespace std;
int N;
long long a;
int t;
int Q;
long long x;
long long mi=0x3f3f3f3f3f3f3f3f;
long long ma=0xcfcfcfcfcfcfcfcf;
long long add;
int main()
{
    scanf("%d",&N);
    while(N--)
    {
        scanf("%lld %d",&a,&t);
        if(t==2)
        {
            ma=max(ma,a);
            mi=max(mi,a);
            continue;
        }
        if(t==3)
        {
            ma=min(ma,a);
            mi=min(mi,a);
            continue;
        }
        mi+=a;
        ma+=a;
        add+=a;
    }
    scanf("%d",&Q);
    while(Q--)
    {
        scanf("%lld",&x);
        printf("%lld ",max(min(mi,x+add),ma));
    }
    printf("\n");
    return 0;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x) cout << (_x) << '\n'; return;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) {}
#endif
#define endl "\n"
template <typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);

//.data

//.code
void SolveTask() {
    int n;
    cin >> n;
    vector<ll> arr(n);
    vector<ll> trr(n);
    loop(n) {
        cin >> arr[i] >> trr[i];
    }
    ll sum = 0;
    vector<pair<ll, ll>> vec;
    for (int i = 0; i < n; ++i) {
        if (trr[i] == 1) {
            sum += arr[i];
        } else {
            arr[i] -= sum;
            if (vec.empty() || vec.back().second != trr[i]) {
                vec.emplace_back(arr[i], trr[i]);
            } else {
                if (trr[i] == 2) {
                    vec.back().first = max(vec.back().first, arr[i]);
                } else {
                    vec.back().first = min(vec.back().first, arr[i]);
                }
            }
        }
    }
    ll lo = LLONG_MAX;
    ll hi = LLONG_MIN;
    int j = -1;
    for (int i = sz(vec) - 1; i >= 0; --i) {
        if (vec[i].second == 2) {
            hi = max(hi, vec[i].first);
        } else {
            lo = min(lo, vec[i].first);
        }
        if (lo <= hi) {
            j = i + 1;
            break;
        }
    }
    ll ans = -1;
    if (j != -1) {
        ans = vec[j].first;
        for (int i = j + 1; i < sz(vec); ++i) {
            if (vec[i].second == 2) {
                ans = max(ans, vec[i].first);
            } else {
                ans = min(ans, vec[i].first);
            }
        }
    }
    int q;
    cin >> q;
    loop(q) {
        ll x;
        cin >> x;
        if (j == -1) {
            cout << max(hi, min(lo, x)) + sum << endl;
        } else {
            cout << ans + sum << endl;
        }
    }
}

int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin("input.txt", std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int test_cases = 1;
    // cin >> test_cases;
    for (int yt = 1; yt <= test_cases; ++yt) {
        SolveTask();
    }
#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}