#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
int k = 0, st[100009] = {}, idx[100009] = {};
void dfs(int i) {
  idx[i] = k;
  k++;
  int d, j, s = 0;
  for (j = 0; j < v[i].size(); j++) {
    d = v[i][j];
    dfs(d);
    s = s + st[d];
  }
  st[i] = s + 1;
  return;
}
int query(int a, int b) {
  int y = st[a];
  a = idx[a];
  b = idx[b];
  int x = a + y - 1;
  if (b >= a && b <= x)
    return y;
  else
    return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b, i, n, m, k, q, ar[100009] = {};
  bool root[100009] = {};
  cin >> n >> m >> k >> q;
  v.resize(n + 1);
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    if (ar[b]) {
      v[ar[b]].push_back(a);
      root[a] = true;
    }
    ar[b] = a;
  }
  for (i = 1; i <= n; i++) {
    if (!root[i]) {
      v[0].push_back(i);
    }
  }
  dfs(0);
  while (q--) {
    cin >> a >> b;
    b = ar[b];
    if (b)
      cout << query(a, b) << "\n";
    else
      cout << "0\n";
  }
  return 0;
}
