#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a) 
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f;
pll a[N]; 
vector<ll> ans;

int main()
{
	IOS;
	int _;
	// cin>>_;
	_ = 1;
	while(_--)
	{
		ll n;
		cin>>n;
		rep1(i, n)	cin>>a[i].X>>a[i].Y;
		sort(a+1, a+1+n);
		ll mi1 = MAX, mi2 = MAX, mx1 = MIN, mx2 = MIN, id1 = 0, id2 = 0;
		rep1(i, n)
		{
			if(a[i].Y <= mi1)	mi2 = mi1, mi1 = a[i].Y, id1 = i;
			else if(a[i].Y <= mi2)	mi2 = a[i].Y;

			if(a[i].Y >= mx1)	mx2 = mx1, mx1 = a[i].Y, id2 = i;
			else if(a[i].Y >= mx2)	mx2 = a[i].Y;
		}
		ans.pb(a[n].X-a[1].X);
		ans.pb(a[n].X-a[2].X);
		ans.pb(a[n-1].X-a[1].X);
		// cout<<id1<<' '<<id2<<nl;
		if(id1 + id2 != n + 1 && (id1 != 1 || id1 != n || id2 != 1 || id2 != n))
			ans.pb(mx1-mi1);//, cout<<"ok?"<<nl;
		ans.pb(mx2-mi1);
		ans.pb(mx1-mi2);
		sort(ans.begin(), ans.end(), greater<ll>());
		cout<<ans[1]<<nl;
	}
	
	
	AC;
} 

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> bool chmin(T& a, T b) {
    if(a > b) { a = b; return true; }
    else return false;
}

template <class T> bool chmax(T& a, T b) {
    if(a < b) { a = b; return true; }
    else return false;
}

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 62;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    ll off = 0, ub = INFL, lb = -INFL;
    while(n--) {
        ll a, t;
        cin >> a >> t;
        if(t == 1) {
            off += a;
        }
        else if(t == 2) {
            a -= off;
            chmax(lb, a);
            if(lb > ub) ub = lb;
        }
        else {
            a -= off;
            chmin(ub, a);
            if(lb > ub) lb = ub;
        }
    }
    ll q;
    cin >> q;
    while(q--) {
        ll x;
        cin >> x;
        if(ub == lb) cout << ub+off << endl;
        else if(x < lb) cout << lb+off << endl;
        else if(ub < x) cout << ub+off << endl;
        else cout << x+off << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}