#include <bits/stdc++.h>
using namespace std;
int now[100005];
int life[100005], times = 0, l[100005], r[100005], sum[100005];
vector<int> vec[100005];
int go(int x, int f) {
  life[x] = f;
  l[x] = ++times;
  sum[x] = 1;
  for (int i = 0; i < vec[x].size(); i++) sum[x] += go(vec[x][i], f + 1);
  r[x] = ++times;
  return sum[x];
}
int main() {
  int n, m, k, q, x, y, ans;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  while (k--) {
    scanf("%d%d", &x, &y);
    if (now[y]) {
      vec[now[y]].push_back(x);
      life[x] = 1;
    }
    now[y] = x;
  }
  for (int i = 1; i <= n; i++) {
    if (!life[i]) go(i, 0);
  }
  while (q--) {
    ans = 0;
    scanf("%d%d", &x, &y);
    if (now[y]) {
      if (l[x] < l[now[y]] && r[x] > r[now[y]]) ans = sum[x];
    }
    printf("%d\n", ans);
  }
  return 0;
}
