#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
vector<int> G[MaxN], euler = {-1};
int n, m, k, q;
int lastWaiting[MaxN], subtreeSize[MaxN], firstAppar[MaxN], lastAppar[MaxN],
    inDeg[MaxN];
void FindSubtreeSize(int vertex) {
  euler.push_back(vertex);
  for (int nxt : G[vertex]) {
    FindSubtreeSize(nxt);
    euler.push_back(vertex);
    subtreeSize[vertex] += subtreeSize[nxt];
  }
}
int main() {
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= k; ++i) {
    int kid, toy;
    cin >> kid >> toy;
    if (lastWaiting[toy]) {
      G[lastWaiting[toy]].push_back(kid);
      ++inDeg[kid];
    }
    lastWaiting[toy] = kid;
  }
  for (int i = 1; i <= n; ++i) {
    subtreeSize[i] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (!inDeg[i]) {
      FindSubtreeSize(i);
    }
  }
  for (int i = 1; i < euler.size(); ++i) {
    int currVertex = euler[i];
    if (!firstAppar[currVertex]) {
      firstAppar[currVertex] = i;
    }
    lastAppar[currVertex] = i;
  }
  for (int i = 1; i <= q; ++i) {
    int kid, toy;
    cin >> kid >> toy;
    int kidDependsOn = lastWaiting[toy];
    if (firstAppar[kidDependsOn] > firstAppar[kid] and
        firstAppar[kidDependsOn] < lastAppar[kid]) {
      cout << subtreeSize[kid] << '\n';
    } else {
      cout << 0 << '\n';
    }
  }
  return 0;
}
