#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7FFFFFFF;
const long long LINF = 0x7FFFFFFFFFFFFF;
void guan() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int maxn = 1010101;
const int mod = 1e9 + 7;
const double eps = 1e-12;
int user[maxn], son[maxn];
vector<int> g[maxn];
int cnt, in[maxn], l[maxn], r[maxn];
void dfs(int rt, int mk) {
  l[rt] = cnt++;
  for (auto v : g[rt]) {
    dfs(v, mk);
    son[rt] += son[v];
  }
  son[rt]++;
  r[rt] = cnt++;
}
int ok(int u, int v) {
  if (l[u] <= l[v] && r[v] <= r[u]) return 1;
  return 0;
}
int main() {
  guan();
  int T, Case = 0;
  int n, k, d, q, m;
  while (cin >> n >> m >> k >> q) {
    int boy, toy;
    memset(user, 0, sizeof(user));
    memset(son, 0, sizeof(son));
    memset(in, 0, sizeof(in));
    memset(in, 0, sizeof(in));
    memset(l, 0, sizeof(l));
    memset(r, 0, sizeof(r));
    cnt = 0;
    for (auto i = (1); i <= (k); ++i) {
      cin >> boy >> toy;
      if (user[toy]) g[user[toy]].push_back(boy), in[boy]++;
      user[toy] = boy;
    }
    for (auto i = (1); i <= (n); ++i)
      if (!in[i]) dfs(i, i);
    for (auto i = (1); i <= (q); ++i) {
      cin >> boy >> toy;
      if (!user[toy])
        cout << 0 << endl;
      else {
        if (ok(boy, user[toy]))
          cout << son[boy] << endl;
        else
          cout << 0 << endl;
      }
    }
  }
  return 0;
}
