#include <bits/stdc++.h>
using namespace std;
const int INF = 1791791791;
const long long INFLL = 1791791791791791791ll;
class dsu {
  vector<int> par;
  vector<int> rank;

 public:
  int cnum;
  dsu() {}
  dsu(int n) {
    cnum = n;
    par.resize(n);
    iota((par).begin(), (par).end(), 0);
    rank.resize(n, 1);
  }
  int get(int u) {
    if (u != par[u]) par[u] = get(par[u]);
    return par[u];
  }
  void merge(int u, int v) {
    u = get(u);
    v = get(v);
    if (u == v) return;
    cnum--;
    if (rank[u] > rank[v]) swap(u, v);
    par[u] = v;
    rank[v] = max(rank[v], rank[u] + 1);
  }
};
class solve {
  int n, k;
  vector<vector<int> > graph;
  vector<dsu> tree;
  void build(int v, int L, int R) {
    tree[v] = dsu(R - L);
    for (int i = (int)(L); i < ((int)(R)); ++i) {
      for (int u : graph[i]) {
        if (L <= u && u < R) tree[v].merge(i - L, u - L);
      }
    }
    if (L != R - 1) {
      build(2 * v + 1, L, (L + R) >> 1);
      build(2 * v + 2, (L + R) >> 1, R);
    }
  }
  vector<tuple<int, int, int> > vertex;
  void get_vertex(int v, int L, int R, int l, int r) {
    if (r <= L || R <= l)
      return;
    else if (l <= L && R <= r)
      vertex.push_back(make_tuple(v, L, R));
    else {
      get_vertex(2 * v + 1, L, (L + R) >> 1, l, r);
      get_vertex(2 * v + 2, (L + R) >> 1, R, l, r);
    }
  }
  int different(vector<int> vec) {
    sort((vec).begin(), (vec).end());
    return distance(vec.begin(), unique((vec).begin(), (vec).end()));
  }
  int on_two_segments(vector<int> fvec, int fl, int fr, vector<int> svec,
                      int sl, int sr) {
    assert(fr == sl);
    vector<int> fcds = fvec;
    sort((fcds).begin(), (fcds).end());
    fcds.resize(distance(fcds.begin(), unique((fcds).begin(), (fcds).end())));
    vector<int> scds = svec;
    sort((scds).begin(), (scds).end());
    scds.resize(distance(scds.begin(), unique((scds).begin(), (scds).end())));
    int m = fcds.size();
    dsu ds(fcds.size() + scds.size());
    for (int i = (int)(fl); i < ((int)(fr)); ++i) {
      for (int u : graph[i])
        if (sl <= u && u < sr)
          ds.merge(
              lower_bound((fcds).begin(), (fcds).end(), fvec[i - fl]) -
                  fcds.begin(),
              m + (lower_bound((scds).begin(), (scds).end(), svec[u - sl]) -
                   scds.begin()));
    }
    return ds.cnum;
  }
  vector<int> segment_comps(int l, int r) {
    vector<int> ans;
    dsu ds(r - l);
    for (int i = (int)(l); i < ((int)(r)); ++i) {
      for (int u : graph[i])
        if (l <= u && u < r) ds.merge(i - l, u - l);
    }
    for (int i = (int)(l); i < ((int)(r)); ++i) ans.push_back(ds.get(i - l));
    return ans;
  }

 public:
  solve(int _n, int _k) {
    n = _n;
    k = _k;
    graph.resize(n);
    tree.resize(4 * n);
  }
  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  void precalc() { build(0, 0, n); }
  int compnum(int l, int r) {
    vertex.clear();
    get_vertex(0, 0, n, l, r);
    int cur = 0;
    vector<int> last;
    int cl = l, cr = l;
    for (auto t : vertex) {
      int v = get<0>(t);
      int L = get<1>(t);
      assert(L == cr);
      int R = get<2>(t);
      int sl = max(cr - k, cl);
      int sr = min(L + k, R);
      int n1 = different(last);
      vector<int> next;
      for (int i = (int)(L); i < ((int)(sr)); ++i)
        next.push_back(tree[v].get(i - L));
      int n2 = different(next);
      cur = cur + tree[v].cnum - (n1 + n2) +
            on_two_segments(last, sl, cr, next, L, sr);
      cr = R;
      if (R - L >= k) {
        last.clear();
        for (int i = (int)(R - k); i < ((int)(R)); ++i)
          last.push_back(tree[v].get(i - L));
      } else
        last = segment_comps(max(cl, cr - k), cr);
    }
    return cur;
  }
};
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  solve prob(n, k);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < ((int)(m)); ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    prob.add_edge(u, v);
  }
  prob.precalc();
  int q;
  scanf("%d", &q);
  for (int i = 0; i < ((int)(q)); ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    printf("%d\n", prob.compnum(l, r));
  }
  return 0;
}
