#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = sum * 10 + ch - '0';
    ch = getchar();
  }
  return sum * t;
}
int n, m, k, q;
int lst[100005];
int nxt[100005], fir[100005], to[100005], cnt;
int sz[100005], bg[100005], ed[100005], dfn;
bool vis[100005];
void add(int x, int y) {
  nxt[++cnt] = fir[x];
  to[cnt] = y;
  fir[x] = cnt;
}
void dfs(int x) {
  sz[x] = 1;
  bg[x] = ++dfn;
  for (int i = fir[x]; i; i = nxt[i]) dfs(to[i]), sz[x] += sz[to[i]];
  ed[x] = dfn;
}
int main() {
  n = read(), m = read(), k = read(), q = read();
  for (int i = 1; i <= k; i++) {
    int x = read(), y = read();
    if (lst[y]) add(lst[y], x), vis[x] = true;
    lst[y] = x;
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  for (; q; q--) {
    int x = read(), y = read();
    if (lst[y] && bg[x] <= bg[lst[y]] && ed[x] >= ed[lst[y]])
      printf("%d\n", sz[x]);
    else
      puts("0");
  }
}
