#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, k, q;
int player[N];
int fa[N];
int in[N], out[N], idx;
vector<int> G[N];
void dfs(int x) {
  in[x] = ++idx;
  for (int i = 0; i < G[x].size(); i++) {
    int next = G[x][i];
    dfs(next);
  }
  out[x] = idx;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (player[b]) {
      fa[a] = player[b];
    }
    player[b] = a;
  }
  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);
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    b = player[b];
    if (in[a] <= in[b] && out[a] >= in[b]) {
      printf("%d\n", out[a] - in[a] + 1);
    } else
      printf("0\n");
  }
  return 0;
}
