#include <bits/stdc++.h>
using namespace std;
long long p[(long long)(2e6 + 5)];
long long t[(long long)(2e6 + 5)];
long long ccc[(long long)(2e6 + 5)], sz[(long long)(2e6 + 5)],
    in[(long long)(2e6 + 5)], out[(long long)(2e6 + 5)];
vector<long long> v[(long long)(2e6 + 5)];
long long cnt;
long long cc;
void dfs(long long u) {
  ccc[u] = cc;
  in[u] = cnt;
  cnt++;
  for (long long i = 0; i < v[u].size(); i++) {
    long long ch = v[u][i];
    dfs(ch);
  }
  out[u] = cnt;
  cnt++;
}
void solve() {
  long long n, m, k, q;
  cin >> n >> m >> k >> q;
  for (long long i = 1; i < n + 1; i++) p[i] = i;
  for (long long i = 1; i < m + 1; i++) t[i] = -1;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    if (t[y] == -1) {
      t[y] = x;
    } else {
      p[x] = t[y];
      v[t[y]].push_back(x);
      t[y] = x;
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    if (p[i] == i) {
      cc++;
      cnt = 0;
      dfs(i);
      sz[cc] = cnt;
    }
  }
  for (long long i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    if (t[y] == -1 || ccc[t[y]] != ccc[x]) {
      cout << 0 << endl;
    } else {
      long long z = t[y];
      swap(x, z);
      if (in[z] < in[x] && out[z] > out[x]) {
        cout << (out[z] - in[z] + 1) / 2 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
}
int main() { solve(); }
