#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
using Graph = vector<vector<ll>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
 

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<ll> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vec a(n),t(n);
    rep(i,n)cin>>a[i]>>t[i];
    ll q;cin>>q;
    multiset<ll> x;
    map<ll,ll> mp;
    rep(i,q){
      ll X;cin>>X;
      x.insert(X);
      mp[i]=X;
    }
    vec ans(q);
    vec it(q,-1);
    ll tot=0;
    map<ll,ll> M;
    rep(i,n){
      if(t[i]==1)tot+=a[i];
      else if(t[i]==2){
        auto itr=x.lower_bound(a[i]-tot+1);
        if(itr==x.begin())continue;
        itr--;
        while(1){
          if(itr==x.begin()){M[*itr]=a[i]-tot;x.erase(itr);break;}
          else{
            M[*itr]=a[i]-tot;
            x.erase(itr--);
          }
        }
        x.insert(a[i]-tot);
        M[a[i]-tot]=a[i]-tot;
      }
      else{
        auto itr=x.lower_bound(a[i]-tot);
        if(itr==x.end())continue;
        while(itr!=x.end()){
          M[*itr]=a[i]-tot;
          x.erase(itr++);
        }
        x.insert(a[i]-tot);
        M[a[i]-tot]=a[i]-tot;
      }
    }
    rep(i,q){
      ll ans=mp[i];
      vec memo;
      while(1){
        if(M.count(ans)){
          if(M[ans]!=ans){
            memo.push_back(ans);
            ans=M[ans];
            }
          else break;
        }
        else break;
      }
      rep(j,memo.size())M[memo[j]]=ans;
      cout<<ans+tot<<endl;
    }
    return 0;
}
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, m; cin >> n >> k >> m;
	int ans = n * m;
	rep(i, n - 1) {
		int a; cin >> a;
		ans -= a;
	}
	if (ans < 0) ans = 0;
	else if (ans > k) ans = -1;
	cout << ans << endl;
}