#include <bits/stdc++.h>
const int maxn = 1e5 + 5;
int n, m, k, q;
std::vector<int> g[maxn];
int in[maxn], out[maxn], vis[maxn], dfs_clock;
void dfs(int u) {
  in[u] = ++dfs_clock;
  for (int i = 0; i < g[u].size(); i++) dfs(g[u][i]);
  out[u] = dfs_clock;
}
int main() {
  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 (vis[y]) g[vis[y]].push_back(x);
    vis[y] = x;
  }
  dfs_clock = 0;
  for (int i = 1; i <= n; i++)
    if (!in[i]) dfs(i);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    y = vis[y];
    if (in[x] <= in[y] && out[x] >= in[y])
      printf("%d\n", out[x] - in[x] + 1);
    else
      puts("0");
  }
}
