#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
struct Two1 {
  lint idx, AB, BA;
  bool operator < (const Two1 &other) const { return AB > other.AB; }
};
struct Two2 {
  lint idx, AB, BA;
  bool operator < (const Two2 &other) const { return BA > other.BA; }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  vector<lint> A(N), B(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  lint score = 0;
  vector<lint> AB;
  vector<lint> BA;
  for(int i=0; i<N; i+=2) {
    if(A[i]+A[i+1] >= B[i]+B[i+1]) {
      score += A[i]+A[i+1];
      AB.push_back(B[i+1]-A[i+1]);
      BA.push_back(B[i]-A[i]);
    } else {
      score += B[i]+B[i+1];
      AB.push_back(A[i]-B[i]);
      BA.push_back(A[i+1]-B[i+1]);
    }
  }
  sort(ALL(AB), greater<lint>());
  sort(ALL(BA), greater<lint>());
  lint ans = score;
  REP(i, AB.size()) {
    score += AB[i] + BA[i];
    chmax(ans, score);
  }
  cout << ans << endl;
}
#include "bits/stdc++.h"
using namespace std;

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define f first
#define s second
#define nl "\n"
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MOD = 1e9+7;
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

int n, q;
ll a, mn, mx, d, t;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);

  mx=1e18;
  mn=-1e18;
  d=0;
  cin >> n;
  rep(i, 1, n){
    cin >> a >> t;
    if(t==1){
      d+=a;
      mn+=a;
      mx+=a;
    }
    else if(t==2){
      if(a>mx) mx=mn=a;
      else if(a>mn) mn=a;
    }
    else{
      if(a<mn) mx=mn=a;
      else if(a<mx) mx=a;
    }
  }

  cin >> q;
  rep(i, 1, q){
    cin >> a;
    cout << min(mx, max(mn, a+d)) << nl;
  }
}