#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
int n, m, k, q;
bool nrt[MaxN];
int own[MaxN];
vector<int> e[MaxN];
int idx[MaxN], sz[MaxN], curidx;
void dfs(int x) {
  idx[x] = ++curidx, sz[x] = 1;
  register int v;
  for (vector<int>::iterator i = e[x].begin(); i != e[x].end(); ++i) {
    v = *i;
    dfs(v);
    sz[x] += sz[v];
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  int x, y;
  for (register int i = 1; i <= k; ++i) {
    scanf("%d%d", &x, &y);
    if (own[y]) e[own[y]].push_back(x), nrt[x] = true;
    own[y] = x;
  }
  for (register int i = 1; i <= n; ++i)
    if (!nrt[i]) {
      dfs(i);
    }
  for (register int i = 1; i <= q; ++i) {
    scanf("%d%d", &x, &y);
    if (own[y] != 0 && idx[x] <= idx[own[y]] &&
        idx[x] + sz[x] >= idx[own[y]] + sz[own[y]])
      printf("%d\n", sz[x]);
    else
      puts("0");
  }
  return 0;
}
