#include <bits/stdc++.h>
using namespace std;
int N, M, K, Q, lst[100005];
int Tm, par[100005], in[100005], out[100005], sub[100005];
vector<int> G[100005];
void dfs(int nd) {
  in[nd] = ++Tm;
  sub[nd] = 1;
  for (int i = 0; i < G[nd].size(); i++) {
    int ch = G[nd][i];
    if (ch == par[nd]) continue;
    dfs(ch);
    sub[nd] += sub[ch];
  }
  out[nd] = ++Tm;
}
int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &K);
  scanf("%d", &Q);
  for (int i = 0; i < K; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    if (lst[b]) {
      par[a] = lst[b];
      G[lst[b]].push_back(a);
    }
    lst[b] = a;
  }
  for (int nd = 1; nd <= N; nd++)
    if (!par[nd]) dfs(nd);
  while (Q--) {
    int u, v, y;
    scanf("%d", &u);
    scanf("%d", &y);
    v = lst[y];
    if (in[v] >= in[u] && out[v] <= out[u]) {
      printf("%d\n", sub[u]);
    } else
      puts("0");
  }
}
