#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
inline long long nxt() {
  long long x;
  cin >> x;
  return x;
}
int n, m, k, q;
vector<int> gr[100500];
int toy[100500];
int last[100500];
int tin[100500];
int tout[100500];
int size[100500];
int parent[100500];
int tottime;
bool in(int x, int z) { return (tin[z] > tin[x] && tout[z] < tout[x]); }
int dfs(int u) {
  tin[u] = tottime++;
  int cursize = 1;
  for (int v : gr[u]) {
    if (tin[v] == -1) cursize += dfs(v);
  }
  tout[u] = tottime++;
  size[u] = cursize;
  return cursize;
}
int main() {
  ios::sync_with_stdio(false);
  memset(toy, -1, sizeof(toy));
  memset(tin, -1, sizeof(tin));
  memset(tout, -1, sizeof(tout));
  n = nxt(), m = nxt(), k = nxt(), q = nxt();
  for (int i = 0; i < k; ++i) {
    int a = nxt(), b = nxt();
    if (toy[b] == -1)
      toy[b] = a;
    else
      gr[last[b]].push_back(a);
    parent[a] = last[b];
    last[b] = a;
  }
  for (int i = 1; i <= n; ++i) {
    if (parent[i] == 0) {
      dfs(i);
    }
  }
  for (int i = 0; i < q; ++i) {
    int x = nxt(), y = nxt();
    int z = last[y];
    if (z == -1 || !in(x, z)) {
      cout << 0 << endl;
    } else {
      cout << size[x] << endl;
    }
  }
  return 0;
}
