#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, k, q;
int x, y, a, b;
vector<int> toy[maxn];
vector<int> G[maxn];
int indexx;
int dfn[maxn], low[maxn];
bool hasfa[maxn];
int son[maxn];
void dfs(int x) {
  dfn[x] = ++indexx;
  son[x] = 1;
  for (int i = 0; i < (int)G[x].size(); i++) {
    int v = G[x][i];
    dfs(v);
    son[x] += son[v];
  }
  low[x] = indexx;
}
int main() {
  cin >> n >> m >> k >> q;
  while (k--) {
    scanf("%d%d", &a, &b);
    if ((int)toy[b].size()) hasfa[a] = true;
    toy[b].push_back(a);
  }
  for (int i = 1; i <= m; i++)
    for (int j = 1; j < (int)toy[i].size(); j++)
      G[toy[i][j - 1]].push_back(toy[i][j]);
  for (int i = 1; i <= n; i++)
    if (!hasfa[i]) dfs(i);
  while (q--) {
    scanf("%d%d", &x, &y);
    if ((int)toy[y].size()) {
      int st = toy[y][toy[y].size() - 1];
      if (dfn[st] > dfn[x] && low[st] <= low[x])
        printf("%d\n", son[x]);
      else
        printf("0\n");
    } else
      printf("0\n");
  }
  return 0;
}
