#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int child, toys, scenes, queries;
vector<int> vec[123456];
int parent[123456], custodyBy[123456], subtree[123456], vis[123456],
    roox[123456], tin[123456], tout[123456];
int tim = 1;
int find_roox(int x) {
  while (roox[x] != x) {
    roox[x] = roox[roox[x]];
    x = roox[x];
  }
  return x;
}
void merge(int x, int y) {
  int u = find_roox(x);
  int v = find_roox(y);
  if (u == v) return;
  roox[u] = v;
}
void dfs(int u) {
  tin[u] = tim++;
  subtree[u] = 1;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (v == parent[u]) continue;
    dfs(v);
    subtree[u] += subtree[v];
  }
  tout[u] = tim++;
}
int main() {
  cin >> child >> toys >> scenes >> queries;
  for (int i = 1; i <= child; i++) {
    roox[i] = i;
  }
  while (scenes--) {
    int boy, toy;
    scanf("%d %d", &boy, &toy);
    if (custodyBy[toy] != 0) {
      int dependOn = custodyBy[toy];
      vec[dependOn].push_back(boy);
      vec[boy].push_back(dependOn);
      parent[boy] = dependOn;
      merge(boy, dependOn);
      custodyBy[toy] = boy;
    } else {
      custodyBy[toy] = boy;
    }
  }
  for (int i = 1; i <= child; i++) {
    if (tin[i] == 0) {
      int root = find_roox(i);
      dfs(root);
    }
  }
  for (int i = 1; i <= child; i++) {
  }
  while (queries--) {
    int boy, toy;
    scanf("%d %d", &boy, &toy);
    int other = custodyBy[toy];
    if (other == 0) {
      printf("0\n");
      continue;
    }
    int u = find_roox(boy);
    int v = find_roox(other);
    if (u != v) {
      printf("0\n");
      continue;
    }
    int ans = 0;
    if (tin[boy] < tin[other] && tout[boy] > tout[other]) {
      ans = subtree[boy];
    }
    printf("%d\n", ans);
  }
}
