#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
int a[maxn], tin[maxn], tout[maxn], n, m, k, q, t = 1;
vector<int> g[maxn];
void dfs(int v) {
  tin[v] = t++;
  for (auto u : g[v]) dfs(u);
  tout[v] = t++;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k >> q;
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    if (a[y]) {
      g[a[y]].push_back(x);
    }
    a[y] = x;
  }
  for (int i = 1; i <= n; ++i)
    if (!tin[i]) dfs(i);
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    if (!a[y]) {
      cout << 0 << "\n";
    } else {
      if (tin[a[y]] > tin[x] && tin[a[y]] < tout[x]) {
        cout << (tout[x] - tin[x] - 1) / 2 + 1 << "\n";
      } else {
        cout << 0 << "\n";
      }
    }
  }
  return 0;
}
