#include <bits/stdc++.h>
using namespace std;
int n, m, k, q, x, y;
int pre[100005], be[100005], en[100005], siz[100005], sum;
bool root[100005];
vector<int> v[100005];
void dfs(int x) {
  ++sum;
  be[x] = sum;
  siz[x] = 1;
  for (int i = 0; i < v[x].size(); ++i) {
    int y = v[x][i];
    dfs(y);
    siz[x] += siz[y];
  }
  en[x] = sum;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= n; ++i) root[i] = true;
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &x, &y);
    if (pre[y] != 0) {
      root[x] = false;
      v[pre[y]].push_back(x);
    }
    pre[y] = x;
  }
  for (int i = 1; i <= n; ++i)
    if (root[i]) dfs(i);
  while (q--) {
    scanf("%d%d", &x, &y);
    if (pre[y] == 0)
      printf("0\n");
    else {
      y = pre[y];
      if (be[y] >= be[x] && be[y] <= en[x])
        printf("%d\n", siz[x]);
      else
        printf("0\n");
    }
  }
  return 0;
}
