#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int n, m, k, q;
vector<pair<int, int> > adj[N];
pair<int, int> request[N];
int cntRequest[N];
vector<int> own[N];
int owner[N];
int wait[N];
int deg[N], root[N];
int h[N], p[N][21];
int timer, timeIn[N], timeOut[N];
int f[N], g[N];
void Free(int u) {
  if (cntRequest[u] > 0) return;
  for (int i = 0; i < (int)own[u].size(); ++i) owner[own[u][i]] = -1;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i].first;
    wait[v] = -1;
    Free(v);
  }
  adj[u].clear();
  own[u].clear();
}
void DFS(int u, int r) {
  timeIn[u] = ++timer;
  root[u] = r;
  for (int i = 1; i <= 20; ++i) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i].first;
    h[v] = h[u] + 1;
    p[v][0] = u;
    DFS(v, r);
  }
  map<int, int> cnt;
  for (int i = (int)adj[u].size() - 1; i >= 0; --i) {
    int v = adj[u][i].first;
    int w = adj[u][i].second;
    cnt[w] += timeOut[v] - timeIn[v] + 1;
    f[v] = cnt[w];
    g[v] = w;
  }
  timeOut[u] = timer;
}
int kthParent(int u, int k) {
  for (int i = 0; i <= 20; ++i)
    if (k >> i & 1) u = p[u][i];
  return u;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= k; ++i)
    scanf("%d%d", &request[i].first, &request[i].second);
  for (int i = 1; i <= k; ++i) cntRequest[request[i].first]++;
  for (int i = 1; i <= m; ++i) owner[i] = -1;
  for (int i = 1; i <= n; ++i) wait[i] = -1;
  for (int i = 1; i <= k; ++i) {
    int u = request[i].first;
    int b = request[i].second;
    cntRequest[u]--;
    if (owner[b] == -1)
      owner[b] = u, own[u].push_back(b);
    else {
      int v = owner[b];
      if (wait[u] == -1) {
        wait[u] = v;
        adj[v].push_back(pair<int, int>(u, b));
      } else {
        int root = u;
        while (wait[root] != -1) root = wait[root];
        Free(root);
        assert(wait[u] == -1);
        if (owner[b] == -1)
          owner[b] = u, own[u].push_back(b);
        else {
          v = owner[b];
          adj[v].push_back(pair<int, int>(u, b));
          wait[u] = v;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) deg[i] = 0;
  for (int u = 1; u <= n; ++u)
    for (int i = 0; i < (int)adj[u].size(); ++i) deg[adj[u][i].first]++;
  for (int i = 1; i <= n; ++i)
    if (deg[i] == 0) DFS(i, i);
  for (int i = 1; i <= q; ++i) {
    int u, b;
    scanf("%d%d", &u, &b);
    if (owner[b] == -1) {
      puts("0");
      continue;
    }
    int v = owner[b];
    int w = root[u];
    if (u == v || timeIn[v] < timeIn[w] || timeOut[w] < timeIn[v])
      printf("%d\n", 0);
    else if (u == w)
      printf("%d\n", timeOut[w] - timeIn[w] + 1);
    else if (timeIn[u] <= timeIn[v] && timeIn[v] <= timeOut[p[u][0]]) {
      v = kthParent(v, h[v] - h[u]);
      if (g[v] != g[u])
        puts("0");
      else
        printf("%d\n", f[u]);
    } else
      printf("%d\n", 0);
  }
  return 0;
}
