#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
int dep[100005], h[100005], to[100005], ne[100005], en = 0;
int hav[100005], in[100005], out[100005], idx = 0, du[100005], siz[100005];
queue<int> qu;
void add(int a, int b) {
  to[en] = b;
  ne[en] = h[a];
  du[b]++;
  h[a] = en++;
}
void dfs(int o) {
  in[o] = ++idx;
  siz[o] = 1;
  for (int i = h[o]; i >= 0; i = ne[i])
    dep[to[i]] = dep[o] + 1, dfs(to[i]), siz[o] += siz[to[i]];
  out[o] = idx;
}
int main() {
  memset(h, -1, sizeof h);
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= k; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (!hav[y])
      hav[y] = x;
    else {
      add(hav[y], x);
      hav[y] = x;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (!du[i]) qu.push(i);
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    dfs(x);
  }
  for (int i = 1; i <= q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (!hav[y])
      printf("0\n");
    else {
      int z = hav[y];
      if (in[z] >= in[x] && out[z] <= out[x]) {
        printf("%d\n", siz[x]);
      } else
        printf("0\n");
    }
  }
}
