#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79;
vector<vector<int> > w(maxn);
vector<int> who(maxn, -1), when(maxn, -1), wait(maxn, -1), tin(maxn, -1),
    tout(maxn);
int timer = 0;
void dfs(int v) {
  tin[v] = timer++;
  for (int i : w[v]) {
    dfs(i);
  }
  tout[v] = timer - 1;
}
bool in_subtree(int p, int v) {
  if (tin[p] <= tin[v] && tout[v] <= tout[p]) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (wait[a] != -1) continue;
    if (who[b] != -1) {
      w[who[b]].push_back(a);
      wait[a] = who[b];
    }
    who[b] = a;
  }
  for (int i = 0; i < n; i++)
    if (tin[i] == -1) dfs(i);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (who[y] == -1) {
      cout << "0\n";
      continue;
    }
    int z = who[y];
    if (in_subtree(x, who[y])) {
      cout << tout[x] - tin[x] + 1 << "\n";
    } else
      cout << "0\n";
  }
  return 0;
}
