#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

class UnionFind {
private:
    vector<int> parent_;
    vector<int> node_rank_;
    vector<int> sizes_;
public:
    UnionFind(int node_num):
        parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
        for (int i = 0; i < node_num; ++i) {
            parent_[i] = i;
            node_rank_[i] = 0;
            sizes_[i] = 1;
        }
    }
    int getRoot(int u) {
        return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
    }
    bool isSame(int u, int v) {
        return getRoot(u) == getRoot(v);
    }
    void unite(int u, int v) {
        u = getRoot(u);
        v = getRoot(v);
        if (u == v) return;
        if (node_rank_[u] < node_rank_[v]) {
            parent_[u] = v;
            sizes_[v] += sizes_[u];
        }
        else {
            parent_[v] = u;
            sizes_[u] += sizes_[v];
            if (node_rank_[u] == node_rank_[v]) {
                node_rank_[u]++;
            }
        }
    }
    int getSize(int u) {
        return sizes_[getRoot(u)];
    }
};

using P = pair<ll, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N), T(N);
    rep(i, 0, N) {
        cin >> A[i] >> T[i];
    }
    int Q;
    cin >> Q;
    vector<ll> X(Q);
    rep(i, 0, Q) {
        cin >> X[i];
    }
    set<P> S;
    rep(i, 0, Q) {
        S.emplace(X[i], i);
    }
    UnionFind uf(Q);
    ll diff = 0;
    rep(i, 0, N) {
        if (T[i] == 1) {
            diff -= A[i];
        } else if (T[i] == 2) {
            // A[i]+diff以下をマージ
            int idx = -1;
            while (!S.empty() && (*S.begin()).first <= A[i] + diff) {
                P now = *S.begin();
                if (idx < 0) {
                    idx = now.second;
                }
                uf.unite(idx, now.second);
                S.erase(now);
            }
            if (idx >= 0) {
                X[idx] = A[i] + diff;
                S.emplace(X[idx], idx);
            }
        } else {
            // A[i]+diff以上をマージ
            int idx = -1;
            while (!S.empty() && (*S.rbegin()).first >= A[i] + diff) {
                P now = *S.rbegin();
                if (idx < 0) {
                    idx = now.second;
                }
                uf.unite(idx, now.second);
                S.erase(now);
            }
            if (idx >= 0) {
                X[idx] = A[i] + diff;
                S.emplace(X[idx], idx);
            }
        }
    }
    rep(i, 0, Q) {
        cout << X[uf.getRoot(i)] - diff << endl;
    }
    return 0;
}
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
// 約数列挙
vector<long long> divisor(long long n) {
	vector<long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end()); // 昇順に並べる
	return ret;
}

// 変数
int n;
int x[210], y[210];
ll r[210];

// スコア計算
ll f(vector<ll>a, vector <ll> b, vector<ll>c, vector<ll>d) {
	long double sum = 0;
	for (int i = 0; i < n; i++) {
		if ((a[i] <= x[i] && x[i] < c[i]) && (b[i] <= y[i] && y[i] <= d[i])) {
			ll now = (c[i] - a[i])*(d[i] - b[i]);
			sum += 1.0 - (1.0 - ((long double)min(now, r[i]) / (long double)max(now, r[i])) * ((long double)min(now, r[i]) / (long double)max(now, r[i])));
		}
	}
	sum /= n;
	sum *= 1e9;
	ll ans = (ll)sum;
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// 入力
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}

	vector<pair<pair<int, int>, pair<ll, int>>>p;
	for (int i = 0; i < n; i++) {
		p.push_back({ {x[i],y[i]}, {r[i], i} });
	}
	sort(p.begin(), p.end());
	vector<int>ansa(n), ansb(n), ansc(n), ansd(n);
	vector<vector<pair<int, pair<ll, int>>>>G(10010);
	for (int i = 0; i < n; i++) {
		G[p[i].first.first].push_back({ p[i].first.second, p[i].second });
	}
	int bx = 0;
	for (int i = 0; i < 10010; i++) {
		int s = G[i].size();
		if (s == 0)continue;
		if (s >= 2) {
			int by = 0;
			for (int j = 0; j < s; j++) {
				int idx = G[i][j].second.second;
				ansa[idx] = bx; ansb[idx] = by;
				ansc[idx] = i + 1; ansd[idx] = G[i][j].first + 1;
				by = G[i][j].first + 1;
			}
		}
		else {
			int idx = G[i][0].second.second;
			int nowr = G[i][0].second.first;
			int tmpy = min(10000, nowr / (i + 1 - bx));
			if (tmpy < G[i][0].first + 1)tmpy = G[i][0].first + 1;
			int now = (i + 1 - bx) * tmpy;
			int K = 0;
			if (now > nowr) {
				int sy = nowr / (i + 1 - bx);
				K = tmpy - sy;
			}
			ansa[idx] = bx; ansb[idx] = K;
			ansc[idx] = i + 1; ansd[idx] = tmpy;
		}
		bx = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << ansa[i] << " " << ansb[i] << " " << ansc[i] << " " << ansd[i] << endl;
	}
	return 0;
}