#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, S, D; cin >> N >> S >> D;
    int X[N], Y[N]; REP(i, N) cin >> X[i] >> Y[i];
    REP(i, N)
    {
        if(X[i] < S && Y[i] > D)
        {
            Yes;
            return 0;
        }
    }
    No;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vll = vector<long long>; using vs = vector<string>;
using vvi = vector<vector<int>>; using vvll = vector<vector<long long>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
void solve1(){

   int n;
   cin >> n;

   vector<pll> at(n);
   for(auto& [a,t]: at) cin >> a >> t;

   int q;
   cin >> q;
   vector<ll> x(q);
   for(auto& y: x) cin >> y;

   auto f = [](const ll x, const ll a, const ll t)->ll{
       if(t==1){
          return x+a;
       }else if(t==2){
          return max(x,a);
       }else{
          return min(x,a);
       }
   };

   for(int i = 0; i < q; ++i){
       ll var = x[i];
       for(int j = 0; j < n; ++j){
          const auto [a,t] = at[j];
           var = f(var, a, t);
       }
       cout << var << endl;
   }
}
void solve2(){

   constexpr ll ll_max = (1LL<<62)+((1LL<<62)-1LL);
   constexpr ll ll_min = -(1LL<<62)-(1LL<<62);

   auto conv = [&](const ll a__, const ll t__)->tuple<ll,ll,ll>{
       ll add, floor__, ceil__;
       if(t__ == 1){
          floor__ = ll_min;
          ceil__ = ll_max;
          add = a__;
       }else if(t__ == 2){
          floor__ = a__;
          ceil__ = ll_max;
          add = 0;
       }else{
          floor__ = ll_min;
          ceil__ = a__;
          add = 0;
       }
       return {add, floor__, ceil__};
   };

   int n;
   cin >> n;

   vector<tuple<ll,ll,ll>> v(n);
   for(int i = 0; i < n; ++i){
      ll a, t;
      cin >> a >> t;
      v[i] = conv(a,t);
   }
   
   auto [add, floor__, ceil__] = v[0];

   for(int i = 1; i < n; ++i){
       
      auto [a2, b2, c2] = v[i];

       if(ceil__ != ll_max){
          ceil__ += a2;
       }
       if(floor__ != ll_min){
          floor__ += a2;
       }
       tie(add, floor__, ceil__) = make_tuple(add+a2, max(b2, floor__), min(c2, max(b2, ceil__)));
   }

   int q;
   cin >> q;
   vector<ll> x(q);
   for(auto& y: x) cin >> y;

   auto f = [](const ll x, const ll add, const ll floor__, const ll ceil__)->ll{
       return min(ceil__, max(floor__, x+add));
   };

   for(int i = 0; i < q; ++i){
       cout << f(x[i], add, floor__, ceil__) << endl;
   }

}
tuple<int,int,int> test(){
   return {1,3,4};
}
void solve3(){

   constexpr ll ll_max = ((1LL<<62)+((1LL<<62)-1LL))/4LL;
   constexpr ll ll_min = (-(1LL<<62)-(1LL<<62))/4LL;

   int n;
   cin >> n;

   ll add = 0, floor__ = ll_min, ceil__ = ll_max;

   for(int i = 0; i < n; ++i){
      ll a, t;
      cin >> a >> t;
      
       if(t == 1){
           floor__ += a;
           ceil__ += a;
           add += a;
       }else if(t == 2){
           floor__ = max(floor__, a);
           //ceil__ = max(ceil__, a);
       }else{
           ceil__ = min(ceil__, a);
           //floor__ = min(floor__, a);
       }
   }
   
   int q;
   cin >> q;
   vector<ll> x(q);
   for(auto& y: x) cin >> y;

   auto f = [](const ll x, const ll add, const ll floor__, const ll ceil__)->ll{
       return min(ceil__, max(floor__, x+add));
   };

   for(int i = 0; i < q; ++i){
       cout << f(x[i], add, floor__, ceil__) << endl;
   }

}
int main(){
    //solve1();
    solve2();
    //solve3();
}
