#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, m, k, q;
vector<int> G[MAXN];
int pre[MAXN];
int belong[MAXN];
int sz[MAXN];
int id[MAXN];
int num = 1;
int dfsclock = 0;
int in[MAXN], out[MAXN];
void dfs(int u, int fa) {
  sz[u] = 1;
  id[u] = num;
  in[u] = ++dfsclock;
  int ee = G[u].size();
  for (int i = 0; i < ee; i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
  out[u] = ++dfsclock;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  memset(pre, -1, sizeof(pre));
  memset(belong, -1, sizeof(belong));
  int a, b;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &a, &b);
    if (belong[b] == -1) {
      belong[b] = a;
      continue;
    }
    pre[a] = belong[b];
    G[a].push_back(belong[b]);
    G[belong[b]].push_back(a);
    belong[b] = a;
  }
  memset(sz, 0, sizeof(sz));
  for (int i = 1; i <= n; i++) {
    if (pre[i] == -1) {
      dfs(i, i);
      num++;
    }
  }
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &a, &b);
    int v = belong[b];
    if (v != -1 && id[a] == id[v] && in[a] < in[v] && out[a] > out[v])
      printf("%d\n", sz[a]);
    else
      puts("0");
  }
  return 0;
}
