#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int n, m, k, q;
vector<int> adj[N];
int owner[N];
int timer, timeIn[N], timeOut[N];
int deg[N];
void DFS(int u) {
  timeIn[u] = ++timer;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    DFS(v);
  }
  timeOut[u] = timer;
}
bool Check(int u, int v) {
  return timeIn[u] <= timeIn[v] && timeIn[v] <= timeOut[u];
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= m; ++i) owner[i] = -1;
  for (int i = 1; i <= k; ++i) {
    int u, b;
    scanf("%d%d", &u, &b);
    if (owner[b] != -1) {
      adj[owner[b]].push_back(u);
      deg[u]++;
    }
    owner[b] = u;
  }
  for (int i = 1; i <= n; ++i)
    if (deg[i] == 0) DFS(i);
  while (q--) {
    int u, b;
    scanf("%d%d", &u, &b);
    if (owner[b] == -1)
      puts("0");
    else
      printf("%d\n", Check(u, owner[b]) ? (timeOut[u] - timeIn[u] + 1) : 0);
  }
  return 0;
}
