#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
vector<vector<int> > g;
vector<int> pr;
vector<bool> rt;
int cnt;
vector<int> in;
vector<int> out;
vector<int> sz;
void path(int u) {
  in[u] = cnt++;
  sz[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    path(v);
    sz[u] += sz[v];
  }
  out[u] = cnt++;
}
int main() {
  cin >> n >> m >> k >> q;
  g.assign(n + 1, vector<int>());
  rt.assign(n + 1, true);
  pr.assign(m + 1, -1);
  sz.resize(n + 1);
  in.resize(n + 1);
  out.resize(n + 1);
  for (int i = 0; i < k; i++) {
    int b, t;
    cin >> b >> t;
    if (pr[t] != -1) {
      g[pr[t]].push_back(b);
      rt[b] = false;
    }
    pr[t] = b;
  }
  cnt = 1;
  for (int i = 1; i <= n; i++) {
    if (rt[i]) {
      path(i);
    }
  }
  for (int i = 0; i < q; i++) {
    int b, t;
    cin >> b >> t;
    int p = pr[t];
    if (p == -1) {
      cout << 0 << "\n";
    } else if (in[b] <= in[p] && out[b] >= out[p]) {
      cout << sz[b] << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
  return 0;
}
