#include <bits/stdc++.h>
struct dsu {
  std::vector<int> repr;
  dsu() {}
  dsu(int size) {
    repr.resize(size);
    for (int i = 0; i < (size); ++i) repr[i] = i;
  }
  int Find(int a) {
    if (a == repr[a]) return a;
    return repr[a] = Find(repr[a]);
  }
  int Union(int a, int b) {
    a = Find(a);
    b = Find(b);
    if (a == b) return 0;
    repr[a] = b;
    return 1;
  }
  int MakeSet() {
    int id = (int)(repr).size();
    repr.push_back(id);
    return id;
  }
};
int bot, n, k;
std::vector<dsu> t;
std::vector<int> ile;
std::vector<std::vector<int> > g;
void go(int v, int lo, int hi) {
  if (hi < n) {
    t[v] = dsu(hi - lo + 1);
    ile[v] = hi - lo + 1;
    for (int i = (lo); i < (hi + 1); ++i) {
      for (auto &ch : (g[i]))
        if (lo <= ch && ch <= hi) {
          ile[v] -= t[v].Union(i - lo, ch - lo);
        }
    }
  }
  int mid = (lo + hi) / 2;
  if (hi != lo) go(v << 1, lo, mid), go((v << 1) + 1, mid + 1, hi);
}
void build() {
  bot = 1;
  while (bot < n) bot *= 2;
  t.resize(bot * 2);
  ile.resize(bot * 2);
  go(1, 0, bot - 1);
}
std::vector<std::pair<int, std::pair<int, int> > > vec;
int query(int a, int b, int v = 1, int lo = 0, int hi = -2) {
  if (hi == -2) hi = bot - 1;
  if (a > b) return 0;
  if (a == lo && b == hi) {
    vec.push_back(std::make_pair(v, std::make_pair(lo, hi)));
    return ile[v];
  }
  int mid = (lo + hi) / 2;
  return query(a, std::min(mid, b), v << 1, lo, mid) +
         query(std::max(a, mid + 1), b, (v << 1) + 1, mid + 1, hi);
}
int answer(int l, int r) {
  vec.clear();
  int ans = query(l, r);
  std::map<std::pair<int, int>, int> map;
  dsu ds;
  std::vector<std::pair<int, int> > guys;
  std::vector<int> kon;
  for (int i = 0; i < ((int)(vec).size()); ++i)
    kon.push_back(vec[i].second.second);
  for (int i = 0; i < ((int)(vec).size()); ++i) {
    int lo = vec[i].second.first;
    int hi = vec[i].second.second;
    for (int j = (lo); j < (std::min(lo + k, hi + 1)); ++j) {
      for (auto &ch : (g[j])) {
        if (ch < l) continue;
        int ind = std::lower_bound(kon.begin(), kon.end(), ch) - kon.begin();
        if (ind == i) continue;
        int ins = ch - vec[ind].second.first;
        std::pair<int, int> my =
            std::make_pair(i, t[vec[i].first].Find(j - lo));
        std::pair<int, int> xd =
            std::make_pair(ind, t[vec[ind].first].Find(ins));
        if (map.count(my) == 0) map[my] = ds.MakeSet();
        if (map.count(xd) == 0) map[xd] = ds.MakeSet();
        ans -= ds.Union(map[xd], map[my]);
      }
    }
  }
  return ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cin >> n >> k;
  g.resize(n);
  int m;
  std::cin >> m;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    if (a < b) std::swap(a, b);
    g[a].push_back(b);
  }
  build();
  int q;
  std::cin >> q;
  while (q--) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    std::cout << answer(a, b) << "\n";
  }
  return 0;
}
