#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5;
bool viz[nmax + 1];
int d[nmax + 1];
int p[nmax + 1], mn[nmax + 1];
int last[nmax + 1], intra[nmax + 1];
int ind;
vector<int> g[nmax + 1];
void dfs(int nod) {
  d[nod] = 1;
  viz[nod] = 1;
  p[nod] = ++ind;
  for (auto i : g[nod]) {
    if (viz[i] == 0) {
      dfs(i);
    }
    d[nod] += d[i];
  }
  mn[nod] = ++ind;
}
int main() {
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x >> y;
    if (last[y]) {
      g[last[y]].push_back(x);
      ++intra[x];
    }
    last[y] = x;
  }
  for (int i = 1; i <= n; ++i) {
    if (intra[i] == 0) {
      dfs(i);
    }
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if (last[y]) {
      if (p[x] <= p[last[y]] && p[last[y]] <= mn[x]) {
        ans = d[x];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
