#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
vector<bool> vis(maxn, 0);
vector<int> tin(maxn), tout(maxn), adj[maxn];
vector<int> ts, last_owner(maxn, -1), st(maxn);
int n, m, k, q, c, t, ctr;
void dfs(int u, int p) {
  if (vis[u]) return;
  tin[u] = ++ctr;
  st[u] = 1;
  vis[u] = 1;
  for (auto v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    st[u] += st[v];
  }
  tout[u] = ++ctr;
}
void topo(int u, int p) {
  if (vis[u]) return;
  vis[u] = 1;
  for (auto v : adj[u])
    if (v != p) topo(v, u);
  ts.push_back(u);
}
bool contains(int u, int v) {
  if (tin[v] > tin[u] and tout[v] < tout[u]) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k >> q;
  for (int i = 0; i < k; i++) {
    cin >> c >> t;
    if (last_owner[t - 1] == -1)
      last_owner[t - 1] = c - 1;
    else {
      adj[last_owner[t - 1]].push_back(c - 1);
      last_owner[t - 1] = c - 1;
    }
  }
  for (int i = 0; i < n; i++) topo(i, -1);
  reverse((ts).begin(), (ts).end());
  for (int i = 0; i < n; i++) vis[i] = 0;
  ctr = 0;
  for (int i = 0; i < n; i++) dfs(ts[i], -1);
  while (q--) {
    cin >> c >> t;
    if (last_owner[t - 1] == -1)
      cout << (0) << endl;
    else
      cout << (contains(c - 1, last_owner[t - 1]) ? st[c - 1] : 0) << endl;
  }
  return 0;
}
