//ΔARC120D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 444444;
int n,a[N],b[N],c[N];
pair<int,int> p[N];
int sz,e[N];
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n*2;i++){
		scanf("%d",a+i);
		p[i]=make_pair(a[i],i);
	}
	sort(p+1,p+n*2+1);
	for(i=1;i<=n;i++)
		b[p[i].second]=1;
	for(i=1;i<=n*2;i++){
		if(!sz){
			e[++sz]=i;
			continue;
		}
		if(b[e[sz]]==b[i])
			e[++sz]=i;
		else
			c[i]=0,c[e[sz]]=1,sz--;
	}
	for(i=1;i<=n*2;i++){
		if(c[i])
			cout<<'(';
		else
			cout<<')';
	}
	return 0;
}
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
// clang-format on
void print(ll v){
  cout << v << endl;
}
ll calc(vector<pll> &task, ll x){
  ll y = x;
  for(auto tsk: task){
    ll a=tsk.first;
    ll t=tsk.second;
    if(t==1){
      y += a;
    }
    if(t==2){
      y = max(y,a);
    }
    if(t==3){
      y = min(y,a);
    }
  }
  return y;
}
      
int main() {
    ll n;
    cin >> n;
    vector<pll> task;
    for (ll i = 0; i < n; i++) {
        ll a, t;
        cin >> a >> t;
        task.push_back({a,t});
    }
    ll ymin = calc(task, -INF);
    ll ymax = calc(task, INF);
  
    // yminと等しくなる最大のx
    ll l = -INF;
    ll r = INF;
    ll xmin = l;
    while(l<=r) { 
      ll x=(l+r)/2;
      if(calc(task,x)==ymin){
        xmin = max(xmin, x);
        l = x+1;
      }else{
        r = x-1;
      }
    }
  
    // ymaxと等しくなる最小のx
    l = -INF;
    r = INF;
    ll xmax = r;
    while(l<=r) { 
      ll x=(l+r)/2;
      if(calc(task,x)==ymax){
        xmax = min(xmax, x);
        r = x-1;
      }else{
        l = x+1;
      }
    }
    if(xmax<xmin) xmax=xmin;

    ll q;
    cin >> q;
    for (ll i = 0; i < q; i++) {
        ll x;
        cin >> x;
        if (x < xmin) {
            print(ymin);
        } else if (x < xmax) {
            print((x - xmin) + ymin);
        } else {
            print(ymax);
        }
    }
}
