#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cctype>
#include <cmath>
#include<deque>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,begin,end) for(int i = begin; i < end; i++)
#define all(c) c.begin(), c.end()
#define ll long long
#define INF 2e9
#define LINF 9223372036854775807
#define cout(n) cout << fixed << setprecision(n)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mod 1000000007;

template<typename T>pair<T, T> max_idx(vector<T>& a) { T ans = 0; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans,index }; return ret; }
template<typename T>pair<T, T> min_idx(vector<T>& a) { T ans = INF; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] < ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans, index }; return ret; }
long long Factorial(int n) { ll sum = 1; for (int i = n; i > 0; i--) { sum *= i; }return sum; }


int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += i;
		if (cnt >= n) {
			cout << i << endl;
			break;
		}
	}
}
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

ll a[300000] = {}, t[300000] = {}, x;

int main() {
	ll ans = 0;
	ll tmp = 0;
	int n; cin >> n;
	REP(i, n) cin >> a[i] >> t[i];
	ll l = -1000000000, h = 1000000000;
	ll off = 0;
	//ll lo = 0, mo = 0, ho = 0;
	REP(i, n){
		if(t[i] == 1){
			off += a[i];
			h += a[i];
			l += a[i];
		}
		if(t[i] == 2){
			l = max(l, a[i]);
			h = max(h, a[i]);
		}
		if(t[i] == 3){
			l = min(l, a[i]);
			h = min(h, a[i]);
		}
		//cout << l << " " << h << " " << off << endl;
	}
	int q; cin >> q;
	REP(i, q){
		cin >> x;
		if(x + off <= l) cout << l << endl;
		else if(x + off >= h) cout << h << endl;
		else cout << x + off << endl;
	}
	///cout << ans << endl;
}