#include <bits/stdc++.h>
using namespace std;
long long n, own[100008], m, k, q, cnt;
int sz[100008], root[100008], low[100008], num[100008];
vector<int> ke[100008];
void nhap() {
  cin >> n >> m >> k >> q;
  for (int x, y, i = 1; i <= k; i++) {
    cin >> x >> y;
    if (own[y]) {
      root[x] = 1;
      ke[own[y]].push_back(x);
    }
    own[y] = x;
  }
}
void dfs(int u) {
  low[u] = ++cnt;
  sz[u] = 1;
  for (int i = 0; i < int(ke[u].size()); i++) {
    int v = ke[u][i];
    dfs(v);
    sz[u] += sz[v];
  }
  num[u] = cnt;
}
void solve() {
  for (int i = 1; i <= n; i++)
    if (!root[i]) dfs(i);
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (!own[y])
      cout << 0 << "\n";
    else {
      int c = own[y];
      if (low[c] >= low[x] && num[c] <= num[x])
        cout << sz[x] << "\n";
      else
        cout << 0 << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  nhap();
  solve();
  return 0;
}
