#include <bits/stdc++.h>
using namespace std;
long long n, m, k, q, a, b, x, y;
long long t1, t2;
bool freee[100111];
long long owner[100111];
long long par[100111];
vector<long long> son[100111];
long long sizedown[100111];
long long tin[100111];
long long tout[100111];
long long ans;
long long dfs(long long v) {
  sizedown[v] = 1;
  ++t1;
  tin[v] = t1;
  for (long long i = 0; i < son[v].size(); ++i) {
    sizedown[v] += dfs(son[v][i]);
  }
  ++t2;
  tout[v] = t2;
  return sizedown[v];
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k >> q;
  for (long long i = 0; i < k; ++i) {
    cin >> a >> b;
    if (freee[b]) {
      freee[b] = false;
      owner[b] = a;
    } else {
      par[a] = owner[b];
      son[owner[b]].push_back(a);
      owner[b] = a;
    }
  }
  for (long long i = 1; i < n + 1; ++i) {
    if (!par[i]) {
      dfs(i);
    }
  }
  for (long long i = 0; i < q; ++i) {
    cin >> x >> y;
    if (freee[y]) {
      cout << "0\n";
    } else if (tin[x] < tin[owner[y]] && tout[x] > tout[owner[y]]) {
      cout << sizedown[x] << '\n';
    } else {
      cout << "0\n";
    }
  }
}
