#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test lli t;cin>>t;while(t--)
#define vll vector<lli>
#define mll map<lli,lli>
#define vvll vector<vector<lli>>
#define vpll vector<pair<lli,lli>>
#define vvpll vector<vector<pair<lli,lli>>>
#define mpll map<pair<lli,lli>,lli>
#define pll pair<lli,lli>
#define sll stack<lli>
#define qll queqe<lli>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
lli h, w, n, m, i, j, k, l, d = 0, x, y;
queue<pll>q;
lli b[1501][1501] = {0};
lli mp[1501][1501] = {0};
vpll v;
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio
  cin >> h >> w >> n >> m;
  while (n--)
  {
    cin >> i >> j;
    v.pb({i, j});
    b[i][j] = 1;
    d++;
    //cout << i << " " << j << endl;
  }
  while (m--)
  {
    cin >> i >> j;
    mp[i][j] = 1;
  }
  for (auto k : v)
  {
    i = k.ff;
    j = k.ss;
    x = i + 1; y = j;
    while (x <= h)
    {
      if (  b[x][y] == 0 && mp[x][y] == 0)
      {
        b[x][y] = 1;
        d++;
        //cout << x << " " << y << endl;
        x++;

      }
      else
        break;
    }
    x = i - 1; y = j;
    while (x > 0)
    {
      if (  b[x][y] == 0 && mp[x][y] == 0)
      {
        b[x][y] = 1;
        d++;
        //cout << x << " " << y << endl;
        x--;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }
  }
  for (auto k : v)
  {
    i = k.ff;
    j = k.ss;
    x = i; y = j + 1;
    while (y <= w)
    {
      if (  b[x][y] != 2 && mp[x][y] == 0)
      {
        if (b[x][y] == 0)
          d++;
        b[x][y] = 2;
        //cout << x << " " << y << endl;
        y++;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }
    x = i; y = j - 1;
    while (y > 0)
    {
      if (  b[x][y] != 2 && mp[x][y] == 0)
      {
        if (b[x][y] == 0)
          d++;
        b[x][y] = 2;

        // cout << x << " " << y << endl;
        y--;
        //cout << i + 1 << " a" << j << endl;
      }
      else
        break;
    }


  }
  cout << d;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, e) for (int i = 0; i < (e); ++i)
#define REP3(i, b, e) for (int i = (b); i < (e); ++i)
#define RREP(i, b, e) for (int i = (b)-1; i >= e; --i)

inline void print(void) {
  cout << '\n';
}

template <class T, class... U>
inline void print(const T &x, const U &...y) {
  cout << x;
  if (sizeof...(U) != 0) {
    cout << ' ';
  }
  print(y...);
}

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<int> t(n);
  REP(i, n) cin >> a[i] >> t[i];

  int q;
  cin >> q;
  vector<long long> x(q);
  REP(i, q) cin >> x[i];

  long long lo = -1000000000LL;
  long long hi = 1000000000LL;

  long long s = 0;
  REP(i, n) {
    if (t[i] == 1) {
      s += a[i];
      lo += a[i];
      hi += a[i];
    } else if (t[i] == 2) {
      lo = max(lo, a[i]);
      hi = max(hi, a[i]);
    } else if (t[i] == 3) {
      lo = min(lo, a[i]);
      hi = min(hi, a[i]);
    }
  }

  REP(i, q) {
    if (x[i] + s <= lo) {
      print(lo);
    } else if (x[i] + s >= hi) {
      print(hi);
    } else {
      print(x[i] + s);
    }
  }

  return 0;
}
