#include <bits/stdc++.h>
using namespace std;
vector<int> ch[100010];
int hold[100010], par[100010], sz[100010], st[100010], ft[100010];
void dfs(int v, int p) {
  static int time = 0;
  ++time;
  st[v] = time;
  par[v] = p;
  sz[v] = 1;
  for (int i = 0; i < ch[v].size(); ++i) {
    dfs(ch[v][i], p);
    sz[v] += sz[ch[v][i]];
  }
  ft[v] = time;
}
int main() {
  int n, m, k, q;
  scanf("%d %d %d %d", &n, &m, &k, &q);
  for (int i = 0; i <= (((m) > (n)) ? (m) : (n)); ++i) par[i] = hold[i] = -1;
  for (int i = 0; i < k; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (hold[b] == -1)
      hold[b] = a;
    else {
      par[a] = hold[b];
      ch[hold[b]].push_back(a);
      hold[b] = a;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (par[i] == -1) dfs(i, i);
  }
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    int v = hold[y];
    if (v == -1)
      printf("0\n");
    else if (par[v] == par[x] && st[x] <= st[v] && ft[v] <= ft[x])
      printf("%d\n", sz[x]);
    else
      printf("0\n");
  }
  return 0;
}
