#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) prllf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
   
int main() {
    ll n;
    cin >> n;

    vector<P> px(n), py(n);
    vl x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
        px[i] = make_pair(x[i], i);
        py[i] = make_pair(y[i], i);
    }
    sort(all(px));
    sort(all(py));

    set<ll> st;
    st.insert(px[0].second);
    st.insert(py[0].second);
    st.insert(px[1].second);
    st.insert(py[1].second);
    st.insert(px[n-1].second);
    st.insert(py[n-1].second);
    st.insert(px[n-2].second);
    st.insert(py[n-2].second);
    vl v;
    for(ll z : st) {
        v.pb(z);
    }
    ll k = v.size();
    vl w;
    exrep(i, 0, k-2) {
        exrep(j, i+1, k-1) {
            w.pb(max(abs(x[v[i]] - x[v[j]]), abs(y[v[i]] - y[v[j]])));
        }
    }
    sort(rall(w)); 
    
    out(w[1]);
    re0;
}
//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define all(s) (s).begin(),(s).end()
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int n;
ll a[200020],t[200020];
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  cin>>n;
  rep(i,n)
  {
    cin>>a[i]>>t[i];
  }
  ll d=0;
  ll maxn=1e18,minn=-1e18;
  rep(i,n)
  {
	if(t[i]==1)
	{
		d+=a[i];
		minn+=a[i];
		maxn+=a[i];
	}
	if(t[i]==2)
	{
		minn=max(minn,a[i]);
		maxn=max(maxn,a[i]);
	} 
	if(t[i]==3)
	{
		minn=min(minn,a[i]);
		maxn=min(maxn,a[i]);
	}
  }
  //cout<<maxn<<" "<<minn<<endl;
  int q;
  cin>>q;
  rep(i,q)
  {
	ll x;
	cin>>x;
	x+=d;
	if(x>maxn)
	{
	  x=maxn;
    }
	if(x<minn)
	{
	  x=minn;
    }
	cout<<x<<endl;
  }
  return 0;
}
/*
注意数组越界，vector长度为0的时候循环会RE
注意输入顺序
注意循环时int*int爆ll
*/



