#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, k, q, dfsclk, fa[maxn], pre[maxn], in[maxn], out[maxn];
vector<int> G[maxn];
void dfs(int u) {
  in[u] = ++dfsclk;
  for (int i = 0; i < G[u].size(); i++) {
    dfs(G[u][i]);
  }
  out[u] = dfsclk;
}
int main() {
  while (~scanf("%d %d %d %d", &n, &m, &k, &q)) {
    for (int i = 0; i < maxn; i++) G[i].clear();
    memset(fa, 0, sizeof(fa));
    memset(pre, 0, sizeof(pre));
    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));
    dfsclk = 0;
    for (int i = 1; i <= k; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (pre[y]) fa[x] = pre[y];
      pre[y] = x;
    }
    for (int i = 1; i <= n; i++) G[fa[i]].push_back(i);
    for (int i = 1; i <= n; i++) {
      if (!in[i]) dfs(i);
    }
    while (q--) {
      int x, y;
      scanf("%d %d", &x, &y);
      y = pre[y];
      if (in[x] <= in[y] && out[x] >= in[y]) {
        printf("%d\n", out[x] - in[x] + 1);
      } else {
        printf("0\n");
      }
    }
  }
  return 0;
}
