#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int N = 200002;
int n, m, k, q, owner[N], ticks, lo[N], hi[N], subsize[N];
vector<int> adj[N];
bool is_root[N];
void dfs(int v) {
  lo[v] = ++ticks;
  subsize[v] = 1;
  for (auto vv : adj[v]) {
    dfs(vv);
    subsize[v] += subsize[vv];
  }
  hi[v] = ticks;
}
bool is_ancestor(int a, int b) { return lo[a] < lo[b] && hi[a] >= hi[b]; }
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 1; i <= n; i++) is_root[i] = true;
  while (k--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (owner[b] != 0) {
      adj[owner[b]].push_back(a);
      is_root[a] = false;
    }
    owner[b] = a;
  }
  for (int i = 1; i <= n; i++)
    if (is_root[i]) dfs(i);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (owner[b] != 0 && is_ancestor(a, owner[b]))
      printf("%d\n", subsize[a]);
    else
      printf("0\n");
  }
  return 0;
}
