#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
int in[100100], out[100100], t;
int bes[100100], sz[100100];
bool root[100100];
vector<int> p[100100];
void dfs(int s) {
  sz[s] = 1, in[s] = ++t;
  for (int i = 0; i < p[s].size(); i++) dfs(p[s][i]), sz[s] += sz[p[s][i]];
  out[s] = ++t;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  memset(root, true, sizeof root);
  for (int i = 0, a, b; i < k; i++) {
    scanf("%d%d", &a, &b);
    if (bes[b]) p[bes[b]].push_back(a), root[a] = false;
    bes[b] = a;
  }
  t = 0;
  for (int i = 1; i <= n; i++)
    if (root[i]) dfs(i);
  int x, y;
  while (q--) {
    scanf("%d%d", &x, &y);
    if (!bes[y])
      puts("0");
    else {
      int s = bes[y];
      if (in[x] < in[s] && out[x] > out[s])
        printf("%d\n", sz[x]);
      else
        puts("0");
    }
  }
  return 0;
}
