#include <bits/stdc++.h>
using namespace std;
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
int n, m, k, q;
int sz[100010], st[100010], root[100010];
vector<int> e[100010];
int in[100010], en[100010], t;
void dfs(int now) {
  in[now] = t++;
  sz[now] = 1;
  for (auto x : e[now]) dfs(x), sz[now] += sz[x];
  en[now] = t;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    if (st[y]) e[st[y]].push_back((x)), root[x] = 1;
    st[y] = x;
  }
  for (int i = 1; i <= n; i++)
    if (not root[i]) dfs(i);
  while (q--) {
    int x, y;
    cin >> x >> y;
    int u = st[y];
    if (in[x] < in[u] && en[u] <= en[x])
      cout << sz[x] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
