#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int n, m, k, q;
int wait[maxn], inuse[maxn], lastreq[maxn];
vector<int> e[maxn];
int l[maxn], r[maxn], fa[maxn], id;
void dfs(int u) {
  l[u] = ++id;
  for (int v : e[u]) dfs(v);
  r[u] = id;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    if (inuse[b] && !wait[a]) {
      wait[a] = b;
      e[fa[a] = lastreq[b]].push_back(a);
    }
    if (!inuse[b]) inuse[b] = a;
    lastreq[b] = a;
  }
  for (int i = 1; i <= n; i++)
    if (fa[i] == 0) dfs(i);
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    if (!inuse[y])
      cout << "0\n";
    else if (l[inuse[y]] < l[x] || l[inuse[y]] > r[x])
      cout << "0\n";
    else
      cout << r[x] - l[x] + 1 << '\n';
  }
  return 0;
}
