#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 9;
vector<int> g[N];
int tin[N];
int tout[N];
int sz[N];
int tt;
int toys[N];
bool root[N];
void dfs(int v) {
  tin[v] = tt++;
  sz[v] = 1;
  for (auto i : g[v]) {
    dfs(i);
    sz[v] += sz[i];
  }
  tout[v] = tt++;
}
bool parent(int v, int p) { return (tin[v] > tin[p] && tout[v] < tout[p]); }
int main() {
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= n; i++) root[i] = true;
  for (int i = 1; i <= k; i++) {
    int v, t;
    cin >> v >> t;
    if (toys[t] == 0) {
      toys[t] = v;
      continue;
    }
    g[toys[t]].push_back(v);
    root[v] = false;
    toys[t] = v;
  }
  for (int i = 1; i <= n; i++)
    if (root[i]) dfs(i);
  for (int i = 1; i <= q; i++) {
    int v, t;
    cin >> v >> t;
    if (toys[t] == 0) {
      cout << 0 << endl;
      continue;
    }
    if (parent(toys[t], v)) {
      cout << sz[v] << endl;
      continue;
    }
    cout << 0 << endl;
  }
  return 0;
}
