#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, M = 1e5;
int dfn, cur[M + 1], in[N + 1], pre[N + 1], fin[N + 1], r[N + 1], sz[N + 1];
vector<int> adj[N + 1];
int dfs(int u, int a) {
  sz[u] = 1;
  r[u] = a;
  pre[u] = ++dfn;
  for (auto v : adj[u]) sz[u] += dfs(v, a);
  fin[u] = ++dfn;
  return sz[u];
}
int main() {
  int n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = (0), i_end = (k); i < i_end; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (cur[b]) {
      ++in[a];
      adj[cur[b]].push_back(a);
    }
    cur[b] = a;
  }
  for (int i = (1), i_end = (n + 1); i < i_end; ++i)
    if (!in[i]) dfs(i, i);
  for (int i = (0), i_end = (q); i < i_end; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    y = cur[y];
    if (r[x] == r[y] && pre[y] > pre[x] && fin[y] < fin[x])
      printf("%d\n", sz[x]);
    else
      puts("0");
  }
  return 0;
}
