#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    rep(i, n){
        int x, y, r;
        cin >> x >> y >> r;
        cout << x << " " << y << " " << x+1 << " " << y+1 << endl;
    }
}
#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll N; cin >> N;
    vector<ll> a(N), t(N);
    rep(i,N) cin >> a[i] >> t[i];
    ll l = -inf, r = inf, add = 0;
    ll L = -inf, R = inf;
    bool is_straight = false;
    rep(i,N) {
        if (t[i]==1) {
            if (is_straight) {
                L += a[i];
                R += a[i];
                continue;
            }
            add += a[i];
            if (l!=-inf) L += a[i];
            if (r!=inf) R += a[i];
        } else if (t[i]==2) {
            if (is_straight) {
                chmax(L,a[i]);
                chmax(R,a[i]);
                continue;
            }
            if (a[i]<=L) continue;
            if (R<=a[i]) {
                L = a[i];
                R = a[i];
                is_straight = true;
                continue;
            }
            L = a[i];
            l = L - add;
        } else {
            if (is_straight) {
                chmin(L,a[i]);
                chmin(R,a[i]);
                continue;
            }
            if (R<=a[i]) continue;
            if (a[i]<=L) {
                L = a[i];
                R = a[i];
                is_straight = true;
                continue;
            }
            R = a[i];
            r = R - add;
        }
    }

    ll Q; cin >> Q;
    vector<ll> res(Q);
    rep(q,Q) {
        ll x; cin >> x;
        if (is_straight) {
            res[q] = L;
        } else {
            if (x<=l) res[q] = L;
            else if (x<r) res[q] = x + add;
            else res[q] = R;
        }
    }
    for (ll ans : res) cout << ans << endl;
}