#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#pragma warning(disable:4996) 

typedef long long ll;
#define LINF 9223300000000000000

using namespace std;

void solve()
{
    int n; cin >> n;
    vector<int> a(n), t(n);
    int i;
    for (i = 0; i < n; i++) cin >> a[i] >> t[i];
    int Q; cin >> Q;
    vector<ll> x(Q);
    for (i = 0; i < Q; i++) cin >> x[i];

    ll offs = 0, M = LINF, m = -LINF;
    for (i = 0; i < n; i++) {
        if (t[i] == 1) offs += a[i];
        else if (t[i] == 2) m = max(m, a[i] - offs), M = max(M, m);
        else M = min(M, a[i] - offs), m = min(m, M);
    }

    for (i = 0; i < Q; i++) {
        x[i] = min(x[i], M);
        x[i] = max(x[i], m);
        cout << x[i]+offs << endl;
    }

    return;
}


int main()
{
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)


signed main(){
    int N ; cin>>N;
    vec_int A(N), B(N); rep(i,N)cin>>A.at(i)>>B.at(i); 

    int ans = INT_MAX;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int temp;
            if(i==j){
                temp = A.at(i) + B.at(i);
            }else{
                temp = max(A.at(i), B.at(j));
            }
            ans = min(temp, ans);
        }
    }
    cout<<ans<<endl;



    return 0;
}