#include <bits/stdc++.h>
using namespace std;
long long Pow(long long a, long long b, long long MOD) {
  a %= MOD;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
const int maxn = 200000 + 10;
const int MOD = 1e9 + 7;
int mp[maxn], vis[maxn], in[maxn], out[maxn], dfs_clock;
vector<int> con[maxn];
void dfs(int u, int b) {
  in[u] = ++dfs_clock;
  for (int i = 0; i < con[u].size(); i++) {
    int v = con[u][i];
    dfs(v, b);
  }
  out[u] = dfs_clock;
}
int main() {
  int i, j, n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  memset(mp, 0, sizeof(mp));
  for (i = 1; i <= k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (mp[b]) {
      con[mp[b]].push_back(a);
    }
    mp[b] = a;
  }
  dfs_clock = 0;
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++) {
    if (in[i]) continue;
    dfs(i, i);
  }
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    y = mp[y];
    if (in[x] <= in[y] && out[x] >= in[y])
      printf("%d\n", out[x] - in[x] + 1);
    else
      printf("0\n");
  }
  return 0;
}
