#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const int sze = 100005;
int n, m, k, q;
vector<int> graphs[sze];
bool isroot[sze];
int whosepossion[sze];
int tin[sze], tout[sze];
int gltime = 1;
int szsubtree[sze];
void dfs(int node) {
  tin[node] = gltime++;
  szsubtree[node] = 1;
  int sz = (int)graphs[node].size();
  for (int i = 0; i < sz; i++) {
    dfs(graphs[node][i]);
    szsubtree[node] += szsubtree[graphs[node][i]];
  }
  tout[node] = gltime++;
}
bool isinsubtree(int a, int b) {
  return tin[b] >= tin[a] && tout[b] <= tout[a];
}
int main() {
  scanf("%d %d %d %d", &n, &m, &k, &q);
  memset(whosepossion, -1, sizeof(whosepossion));
  memset(isroot, true, sizeof(isroot));
  memset(tin, 0, sizeof(tin));
  memset(tout, 0, sizeof(tout));
  int i, j;
  int t1, t2;
  for (i = 1; i <= k; i++) {
    scanf("%d %d", &t1, &t2);
    if (whosepossion[t2] == -1) {
    } else {
      int id = whosepossion[t2];
      graphs[id].push_back(t1);
      isroot[t1] = false;
    }
    whosepossion[t2] = t1;
  }
  for (i = 1; i <= n; i++) {
    if (isroot[i]) dfs(i);
  }
  for (i = 1; i <= q; i++) {
    scanf("%d %d", &t1, &t2);
    if (whosepossion[t2] == -1) {
      printf("0\n");
    } else {
      int id = whosepossion[t2];
      if (isinsubtree(t1, id)) {
        printf("%d\n", szsubtree[t1]);
      } else {
        printf("0\n");
      }
    }
  }
  return 0;
}
