#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 2 * N;
int edge[M], succ[M], ver[N], idx;
int in[N], out[N], time_stamp;
int fnl[N];
void add(int u, int v) {
  edge[idx] = v;
  succ[idx] = ver[u];
  ver[u] = idx++;
}
void dfs(int u, int fa = -1) {
  in[u] = ++time_stamp;
  for (int i = ver[u]; ~i; i = succ[i]) {
    int v = edge[i];
    if (v == fa) continue;
    dfs(v, u);
  }
  out[u] = time_stamp;
}
int main() {
  memset(ver, -1, sizeof ver);
  int n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= k; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (fnl[b]) add(fnl[b], a);
    fnl[b] = a;
  }
  for (int i = 1; i <= n; ++i)
    if (!in[i]) dfs(i);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    b = fnl[b];
    if (in[a] <= in[b] && in[b] <= out[a])
      printf("%d\n", out[a] - in[a] + 1);
    else
      puts("0");
  }
  return 0;
}
