#include <bits/stdc++.h>
using namespace std;
int N, Q;
const int maxn = 2e5 + 5;
typedef long long ll;
inline ll read()
{
    ll x = 0;
    int s = 1;
    char c = getchar();
    while (c < 48 || c > 57)
    {
        if (c == '-')
            s = -1;
        c = getchar();
    }
    while (c >= 48 && c <= 57)
    {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return x * s;
}
int main()
{
    int N, Q;
    N = read();
    ll a, t;
    ll l = -1e9, r = 1e9, b = 0;
    for (int i = 0; i < N; i++)
    {
        a = read();
        t = read();
        if (t == 1)
        {
            l += a;
            r += a;
            b += a;
        }
        else if (t == 2)
        {
            l = max(l, a);
            r = max(r, a);
        }
        else
        {
            l = min(l, a);
            r = min(r, a);
        }
    }
    Q = read();
    while (Q--)
    {
        ll x = read() + b;
        if (x < l)
            cout << l;
        else if (x > r)
            cout << r;
        else
            cout << x;
        cout << ' ';
    }
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

int main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<a+b+c-min({a,b,c})<<endl;
}
