#include <bits/stdc++.h>
using namespace std;
int n, m, c;
vector<int> G[100005];
int taken[100005];
int component[100005];
int totchild[100005];
int parent[20][100005];
int depth[100005];
int dfs(int node, int h) {
  depth[node] = h;
  component[node] = c;
  totchild[node] = 1;
  for (auto next : G[node]) {
    totchild[node] += dfs(next, h + 1);
  }
  return totchild[node];
}
void init() {
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) parent[i][j] = parent[i - 1][parent[i - 1][j]];
}
int move_up(int a, int height) {
  if (height == 0) return a;
  int best = floor(log2(height));
  return move_up(parent[best][a], height - (1 << best));
}
int lca(int a, int b) {
  if (depth[a] > depth[b]) a = move_up(a, depth[a] - depth[b]);
  if (depth[b] > depth[a]) b = move_up(b, depth[b] - depth[a]);
  int k = ceil(log2(n)), ans;
  while (k >= 0) {
    if (a == b) return a;
    if (k == 0 && parent[0][a] == parent[0][b]) return parent[0][a];
    if (!parent[k][a] || !parent[k][b] || (parent[k][a] == parent[k][b]))
      k--;
    else {
      a = parent[k][a];
      b = parent[k][b];
    }
  }
  return ans;
}
int main() {
  int i, j, k, q, a, b, l;
  scanf("%d %d %d %d", &n, &m, &k, &q);
  while (k--) {
    scanf("%d %d", &a, &b);
    if (!taken[b]) {
      taken[b] = a;
    } else {
      parent[0][a] = taken[b];
      G[taken[b]].push_back(a);
      taken[b] = a;
    }
  }
  for (i = 1; i <= n; i++)
    if (!parent[0][i]) {
      ++c;
      dfs(i, 1);
    }
  init();
  while (q--) {
    scanf("%d %d", &a, &b);
    b = taken[b];
    if (component[a] != component[b])
      printf("0\n");
    else {
      l = lca(a, b);
      if (l == a)
        printf("%d\n", totchild[a]);
      else
        printf("0\n");
    }
  }
  return 0;
}
