#include <bits/stdc++.h>
using namespace std;
int n, m, k, q;
vector<vector<int> > graph;
vector<int> toy;
vector<int> child;
vector<int> tin, tout;
vector<int> sub;
int tim = 0;
void preprocess(void) { return; }
void dfs(int cur, int p) {
  tin[cur] = tim++;
  sub[cur] = 1;
  for (int i = 0; i < (int)graph[cur].size(); i++) {
    int u = graph[cur][i];
    if (u != p) {
      dfs(u, cur);
      sub[cur] += sub[u];
    }
  }
  tout[cur] = tim++;
}
int main(void) {
  preprocess();
  int t;
  t = 1;
  for (int z = 1; z <= t; z++) {
    scanf("%d", &n), scanf("%d", &m), scanf("%d", &k), scanf("%d", &q);
    graph.resize(n + 1);
    toy.assign(m + 1, -1);
    child.assign(n + 1, -1);
    tin.assign(n + 1, 0), tout.assign(n + 1, 0);
    sub.assign(n + 1, 0);
    for (int i = 0; i < k; i++) {
      int a, b;
      scanf("%d", &a), scanf("%d", &b);
      if (toy[b] == -1) {
        toy[b] = a;
      } else {
        graph[toy[b]].push_back(a);
        child[a] = toy[b];
      }
      toy[b] = a;
    }
    for (int i = 0; i < n; i++) {
      if (child[i + 1] == -1) {
        dfs(i + 1, -1);
      }
    }
    for (int i = 0; i < q; i++) {
      int a, b;
      scanf("%d", &a), scanf("%d", &b);
      int c = toy[b];
      if (c == -1) {
        printf("%d\n", 0);
      } else {
        if (tin[a] <= tin[c] && tout[a] >= tout[c]) {
          printf("%d\n", sub[a]);
        } else {
          printf("%d\n", 0);
        }
      }
    }
  }
  return 0;
}
