#include <bits/stdc++.h>
using namespace std;
struct DisjointSet {
  vector<int> p, r;
  int c;
  DisjointSet(int n) : p(n, 0), r(n, 0), c(n) {
    for (auto i = (0); i < (n); i++) p[i] = i;
  }
  int find(int a) {
    int x = a;
    while (p[x] != x) x = p[x];
    while (p[a] != x) {
      int pa = p[a];
      p[a] = x;
      a = pa;
    }
    return x;
  }
  void unio(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    c--;
    if (r[a] < r[b])
      p[a] = b;
    else if (r[a] > r[b])
      p[b] = a;
    else {
      p[b] = a;
      r[a]++;
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  int n, k, m;
  cin >> n >> k >> m;
  vector<set<int>> graph(n);
  vector<vector<DisjointSet>> ds;
  int d = 1, c = 0;
  while (d <= n) {
    ds.emplace_back();
    for (auto i = (0); i < ((n + d - 1) / d); i++) ds.back().emplace_back(d);
    d <<= 1;
    c++;
  }
  for (auto i = (0); i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].insert(b);
    graph[b].insert(a);
    for (auto c = ((int)ds.size()) - 1; c >= (0); c--) {
      if ((a >> c) != (b >> c)) break;
      ds[c][a >> c].unio(a - ((a >> c) << c), b - ((b >> c) << c));
    }
  }
  int q;
  cin >> q;
  for (auto i = (0); i < (q); i++) {
    int l, r;
    cin >> l >> r;
    if (l-- == r) {
      cout << 1 << endl;
      continue;
    }
    int f = 0;
    map<int, int> ind;
    auto getind = [&](int a) {
      auto it = ind.find(a);
      if (it != ind.end()) return it->second;
      ind[a] = f;
      return f++;
    };
    DisjointSet ds2(512);
    int ret = 0;
    vector<tuple<int, int, int>> prev;
    prev.emplace_back(0, 0, -1);
    auto merge = [&]() {
      ret += ds[c][l >> c].c;
      for (auto pi = ((int)prev.size()) - 1; pi >= (0); pi--) {
        int pl, pr, pc;
        tie(pl, pr, pc) = prev[pi];
        if (pr < l - k) break;
        for (auto a = (max(pl, l - k)); a < (pr); a++)
          for (auto b = (l); b < (l + min(d, k)); b++) {
            if (graph[a].count(b))
              ds2.unio(getind(ds[pc][a >> pc].find(a - ((a >> pc) << pc)) +
                              ((a >> pc) << pc)),
                       getind(ds[c][b >> c].find(b - ((b >> c) << c)) +
                              ((b >> c) << c)));
          }
      }
      prev.emplace_back(l, l + d, c);
      l += d;
    };
    c = 0, d = 1;
    while (d <= r - l) {
      if (l & d) merge();
      d <<= 1;
      c++;
    }
    while (d > 0) {
      d >>= 1;
      c--;
      if ((r - l) & d) merge();
    }
    cout << (ret + ds2.c - 512) << endl;
  }
  return 0;
}
