#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int n, m, k, q, tot, fir[M], las[M], reg[M], in[M], out[M], siz[M], dfs_clock;
bool vis[M];
struct edge {
  int v, nex;
} e[M << 1];
void add(int u, int v) {
  e[++tot] = (edge){v, fir[u]};
  fir[u] = tot;
}
void dfs(int u) {
  siz[u] = vis[u] = 1;
  in[u] = ++dfs_clock;
  for (int i = fir[u]; i; i = e[i].nex) {
    int v = e[i].v;
    dfs(v);
    siz[u] += siz[v];
  }
  out[u] = dfs_clock;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    if (las[y]) {
      out[x]++;
      add(las[y], x);
    }
    las[y] = x;
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i] && !out[i]) dfs(i);
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    y = las[y];
    if (in[y] >= in[x] && in[y] <= out[x])
      cout << siz[x] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
