#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

long long n,tot;
struct node{
	long long x,y,id;
}a[200010],b[200010];
struct fk{
	long long w,id;
}f[10];

bool cx(node u,node v){
	return u.x<v.x;
}
bool cy(node u,node v){
	return u.y<v.y;
}
bool cf(fk u,fk v){
	return u.w<v.w;
}

int main(){
	long long i,j,u,v;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
		a[i].id=i;
	}
	memcpy(b,a,sizeof(b));
	sort(a+1,a+n+1,cx);
	sort(b+1,b+n+1,cy);
	f[0].w=a[n].x-a[1].x;
	f[0].id=a[n].id*200010+a[1].id;
	f[1].w=a[n].x-a[2].x;
	f[1].id=a[n].id*200010+a[2].id;
	f[2].w=a[n-1].x-a[1].x;
	f[2].id=a[n-1].id*200010+a[1].id;
	f[3].w=b[n].y-b[1].y;
	f[3].id=b[n].id*200010+b[1].id;
	f[4].w=b[n].y-b[2].y;
	f[4].id=b[n].id*200010+b[2].id;
	f[5].w=b[n-1].y-b[1].y;
	f[5].id=b[n-1].id*200010+b[1].id;
	sort(f,f+6,cf);
	if(f[4].id!=f[5].id) cout<<f[4].w<<endl;
	else cout<<f[3].w<<endl;
	return 0;
}
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;

#define int long long
#define pii pair<int,int>
#define float long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define uid uniform_int_distribution<int>
#define forn(i,st,n,inc) for(int i=st;i<n;i+=inc)
#define rforn(i,st,n,inc) for(int i=st-1;i>=n;i-=inc)
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define ordSet tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const int MOD = 1e9+7;//998244353;
const int64_t LLINF = 1e18+7;
const int32_t INF = 1e9+7;

ostream& operator<<(ostream& o,const string& s){
    for(auto c:s) o<<c;
    return o;
}

template<typename F,typename S>
ostream& operator<<(ostream& o,const pair<F,S>& p){
    o<<"["<<p.fi<<","<<p.se<<"]";
    return o;
}

template<typename... T,template<class...> class C>
ostream& operator<<(ostream& o,const C<T...>& v){
    o<<"[";
    int tot=0;
    for(auto x:v){ 
        o<<x;
        if(tot<v.size()-1) o<<",";
        tot++;
    }
    o<<"]";
    return o;
}

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef OFFLINE
clock_t Tm=clock();
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...)
#endif

const int MAXN = 2e5+7, MAXX= 1e9;
int n;
int lx=-MAXX,ly=lx;
int rx=-lx,ry=rx;

void domax(int a){
    if(a<=ly) return;
    if(a>=ry){ 
        ly=ry=a;
        lx=-MAXX;
        rx=MAXX;
    }
    lx=a-(ry-rx);
    ly=a;
}

void domin(int a){
    if(a>=ry) return;
    if(a<=ly){ 
        ly=ry=a;
        lx=-MAXX;
        rx=MAXX;
    }
    rx=a-(ly-lx);
    ry=a;
}

int f(int x){
    if(x<=lx) return ly;
    if(x>=rx) return ry;
    return x+(ry-rx);
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie();
    //If you hack my code , You are gay
    cin>>n;
    for(int i=0;i<n;i++){
        int a,t;
        cin>>a>>t;
        if(t==1) ly+=a,ry+=a;
        else if(t==2) domax(a);
        else domin(a);
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int x;
        cin>>x;
        cout<<f(x)<<"\n";
    }
    //mara kha
    #ifdef OFFLINE
        cerr<<"Time = "<<(double)(clock()-Tm)/CLOCKS_PER_SEC;
    #endif
    return 0;
}