#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int p[100005];
int a[100005], b[100005];
vector<int> edges[100005];
vector<int> rev[100005];
int last[100005];
bool inc[100005];
bool visited[100005];
queue<int> qu;
int cnt, num;
int dfs_num[100005];
int dfs_low[100005];
int child[100005];
void init(int n) {
  for (int i = 1; i <= n; ++i) p[i] = i;
}
int find(int a) {
  if (a != p[a]) p[a] = find(p[a]);
  return p[a];
}
void un(int a, int b) {
  int c = find(a);
  int d = find(b);
  if (c != d) {
    p[c] = d;
  }
}
void dfs(int a) {
  dfs_num[a] = dfs_low[a] = ++cnt;
  visited[a] = 1;
  child[a]++;
  int nxt;
  for (int i = 0; i < rev[a].size(); ++i) {
    nxt = rev[a][i];
    if (!dfs_num[nxt]) dfs(nxt);
    if (visited[nxt]) dfs_low[a] = max(dfs_low[a], dfs_low[nxt]);
    child[a] += child[nxt];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, k, q;
  int x, y;
  while (cin >> n >> m >> k >> q) {
    memset(last, -1, sizeof(last));
    memset(inc, 0, sizeof(inc));
    init(n);
    for (int i = 0; i < k; ++i) {
      cin >> a[i] >> b[i];
      if (last[b[i]] != -1) {
        edges[a[i]].push_back(last[b[i]]);
        un(a[i], last[b[i]]);
      }
      last[b[i]] = a[i];
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < edges[i].size(); ++j) {
        rev[edges[i][j]].push_back(i);
        inc[i] = 1;
      }
    }
    num = cnt = 0;
    memset(dfs_num, 0, sizeof(dfs_num));
    memset(dfs_low, 0, sizeof(dfs_low));
    memset(child, 0, sizeof(child));
    memset(visited, 0, sizeof(visited));
    for (int i = 1; i <= n; ++i) {
      if (!inc[i]) dfs(i);
    }
    for (int i = 0; i < q; ++i) {
      cin >> x >> y;
      y = last[y];
      if (y == -1)
        cout << "0\n";
      else {
        if (find(y) != find(x))
          cout << "0\n";
        else {
          if (dfs_num[x] < dfs_num[y] && dfs_num[y] <= dfs_low[x]) {
            cout << child[x] << "\n";
          } else
            cout << "0\n";
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      edges[i].clear();
      rev[i].clear();
    }
  }
  return 0;
}
