#include <bits/stdc++.h>
using namespace std;
int n, m, k, q, ck[100010], x, y, pr[100010], sum[100010], in[100010],
    out[100010], c;
vector<int> adj[100010];
void dfs(int node) {
  in[node] = c++;
  for (auto p : adj[node]) {
    dfs(p);
    sum[node] += sum[p];
  }
  sum[node]++;
  out[node] = c++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m >> k >> q;
  memset(ck, -1, sizeof ck);
  memset(pr, -1, sizeof pr);
  for (int i = 1; i <= k; i++) {
    cin >> x >> y;
    x--;
    y--;
    if (ck[y] != -1) {
      adj[ck[y]].push_back(x);
      pr[x] = ck[y];
    }
    ck[y] = x;
  }
  for (int i = 0; i <= n - 1; i++) {
    if (pr[i] == -1) {
      dfs(i);
    }
  }
  int ans = 0;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    x--;
    y--;
    if (in[x] < in[ck[y]] && out[x] > out[ck[y]])
      cout << sum[x] << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
