#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
bool read() {
  if (scanf("%d%d%d%d", &n, &m, &k, &q) < 4) {
    return 0;
  }
  return 1;
}
vector<vector<int> > sons;
vector<int> sz;
vector<int> par;
vector<int> tin;
vector<int> tout;
int timer;
void addE(int v, int to) {
  sons[to].push_back(v);
  assert(par[v] == -1);
  par[v] = to;
}
void dfs_sz(int v) {
  tin[v] = timer++;
  sz[v] = 1;
  for (int to : sons[v]) {
    dfs_sz(to);
    sz[v] += sz[to];
  }
  tout[v] = timer++;
}
bool is_upper(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
void solve() {
  sz.assign(n, 0);
  par.assign(n, -1);
  sons.assign(n, vector<int>());
  vector<int> last(m, -1);
  for (int it = 0; it < int(k); ++it) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if (last[b] != -1) {
      addE(a, last[b]);
    }
    last[b] = a;
  }
  vector<int> roots;
  for (int v = 0; v < int(n); ++v) {
    if (par[v] == -1) {
      roots.push_back(v);
    }
  }
  tin.assign(n, 0);
  tout.assign(n, 0);
  timer = 0;
  for (int r : roots) {
    dfs_sz(r);
  }
  vector<int> ans(q, 0);
  for (int i = 0; i < int(q); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if (last[b] == -1) {
      continue;
    }
    int v = a;
    int to = last[b];
    if (!is_upper(v, to)) {
      continue;
    }
    ans[i] = sz[v];
  }
  for (int i = 0; i < int(q); ++i) {
    printf("%d\n", ans[i]);
  }
}
int main() {
  while (read()) {
    solve();
  }
  return 0;
}
