#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFL = 1001001001001001001LL;
template <typename T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int in() {
  int x;
  cin >> x;
  return x;
}
double fin() {
  double x;
  cin >> x;
  return x;
}
string sin() {
  string x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
const int maxn = 100010;
const int maxm = 100010;
int n, m, k, q;
int occ[maxm];
int dep[maxn];
vector<int> rev[maxn];
int ngrp;
int visited[maxn];
int cnt[maxn];
int pre[maxn];
int post[maxn];
int precnt, postcnt;
void dfs(int c) {
  visited[c] = 1;
  cnt[c] = 1;
  pre[c] = ++precnt;
  for (int v : rev[c]) {
    if (!visited[v]) {
      dfs(v);
    }
    cnt[c] += cnt[v];
  }
  post[c] = ++postcnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(20);
  cin >> n >> m >> k >> q;
  memset(occ, -1, sizeof(occ));
  memset(dep, -1, sizeof(dep));
  for (int i = 0; i < (int)(k); ++i) {
    int p, t;
    cin >> p >> t;
    p--;
    t--;
    if (occ[t] != -1) {
      dep[p] = occ[t];
    }
    occ[t] = p;
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (dep[i] != -1) rev[dep[i]].push_back(i);
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (dep[i] == -1) {
      dfs(i);
    }
  }
  for (int i = 0; i < (int)(q); ++i) {
    int p, t;
    cin >> p >> t;
    p--;
    t--;
    if (occ[t] == -1) {
      cout << 0 << '\n';
    } else {
      if (pre[occ[t]] > pre[p] && post[occ[t]] < post[p]) {
        cout << cnt[p] << '\n';
      } else {
        cout << 0 << '\n';
      }
    }
  }
  return 0;
}
