#include <bits/stdc++.h>
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
long long n, m, k, q, l, r, x, y, z;
const long long template_array_size = 1e6 + 8432;
long long a[template_array_size];
long long b[template_array_size];
long long c[template_array_size];
string second, t;
long long ans = 0;
vector<long long> edges[100005];
long long chain[100005], pos[100005], nxt[100005], csz[100005], vis[100005];
long long T = -1, st[100005], en[100005], sz[100005];
long long dfs(long long v, long long g) {
  st[v] = ++T;
  sz[v] = 1;
  chain[v] = g;
  for (long long x : edges[v]) sz[v] += dfs(x, g);
  en[v] = T;
  return sz[v];
}
void solve(int tc = 0) {
  cin >> n >> m >> k >> q;
  memset(vis, -1, sizeof(vis));
  memset(nxt, -1, sizeof(nxt));
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    --x;
    --y;
    if (vis[y] != -1) {
      nxt[x] = vis[y];
      edges[vis[y]].push_back(x);
    }
    vis[y] = x;
  }
  long long gz = 1;
  for (long long i = 0; i < n; i++) {
    if (nxt[i] == -1) {
      dfs(i, gz++);
    }
  }
  for (long long i = 0; i < q; i++) {
    cin >> x >> y;
    --x;
    --y;
    long long ans = 0;
    if (vis[y] != -1) {
      if (chain[x] == chain[vis[y]] && vis[y] != x) {
        if (st[x] <= st[vis[y]] && en[vis[y]] <= en[x]) {
          ans = sz[x];
        }
      }
    }
    cout << ans << '\n';
  }
}
int main() {
  { ios_base::sync_with_stdio(false); }
  { cin.tie(NULL); }
  cout << setprecision(15) << fixed;
  int tc = 1;
  for (int t = 0; t < tc; t++) solve(t);
}
