#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007, oo = 1000000009;
void Emsawy() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
vector<vector<int> > adj;
const long long N = 100000 + 5;
int n, m, k, w, q;
int lst[N], ans[N], in[N], inp[N], oup[N], st;
int go(int nd) {
  ans[nd] = 1;
  inp[nd] = st++;
  for (int i = 0; i < adj[nd].size(); i++) {
    ans[nd] += go(adj[nd][i]);
  }
  oup[nd] = st++;
  return ans[nd];
}
int main() {
  Emsawy();
  while (cin >> n >> m >> k >> q) {
    int u, v;
    adj.clear();
    adj.resize(n + 1);
    for (int i = 0; i < k; i++) {
      cin >> u >> v;
      if (lst[v] == 0) {
        lst[v] = u;
        continue;
      }
      adj[lst[v]].push_back(u);
      in[u] = 1;
      lst[v] = u;
    }
    for (int i = 1; i <= n; i++) {
      if (in[i] == 0) {
        go(i);
      }
    }
    for (int i = 0; i < q; i++) {
      cin >> u >> v;
      if (lst[v] == 0)
        cout << 0 << endl;
      else if (inp[u] <= inp[lst[v]] && oup[u] >= oup[lst[v]])
        cout << ans[u] << endl;
      else
        cout << 0 << endl;
    }
  }
  return 0;
}
