#include <bits/stdc++.h>
using namespace std;
int p[100005];
vector<int> children[100005];
int last[100005];
int l[100005];
int r[100005];
int sz[100005];
int t;
void dfs(int node) {
  l[node] = t++;
  sz[node] = 1;
  for (int c : children[node]) {
    dfs(c);
    sz[node] += sz[c];
  }
  r[node] = t++;
}
int main(void) {
  int n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  for (int i = 0; i < m; ++i) {
    last[i] = -1;
  }
  for (int i = 0; i < k; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    p[a] = last[b];
    if (p[a] != -1) {
      children[p[a]].push_back(a);
    }
    last[b] = a;
  }
  t = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] == -1) {
      dfs(i);
    }
  }
  for (int i = 0; i < q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (last[y] == -1) {
      cout << 0 << endl;
      continue;
    }
    int j = last[y];
    if (l[j] > l[x] && r[j] < r[x]) {
      cout << sz[x] << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
