#include <bits/stdc++.h>
using namespace std;
struct Node {
  int numComp;
  vector<pair<int, int> > lft;
  vector<pair<int, int> > rgt;
};
Node dft;
int n, K, m;
vector<int> a[100010];
Node T[4 * 100010];
set<pair<int, int> > edges;
int pr[100010];
vector<int> temp;
int getParent(int u) {
  if (pr[u] == u) return u;
  if (pr[u] == 0) return u;
  temp.push_back(u);
  return pr[u] = getParent(pr[u]);
}
Node joinNode(Node T1, Node T2, int l, int r) {
  Node res;
  temp.clear();
  for (auto x : T1.lft) {
    pr[x.first] = x.second;
    temp.push_back(x.first);
  }
  for (auto x : T1.rgt) {
    pr[x.first] = x.second;
    temp.push_back(x.first);
  }
  for (auto x : T2.lft) {
    pr[x.first] = x.second;
    temp.push_back(x.first);
  }
  for (auto x : T2.rgt) {
    pr[x.first] = x.second;
    temp.push_back(x.first);
  }
  res.numComp = T1.numComp + T2.numComp;
  int mid = (l + r) / 2;
  for (auto pu : T1.rgt) {
    int u = pu.first;
    for (int v : a[u]) {
      if (v <= mid || pr[v] == 0) continue;
      int du = getParent(u);
      int dv = getParent(v);
      if (du != dv) {
        res.numComp--;
        pr[du] = dv;
        temp.push_back(du);
      }
    }
  }
  for (auto x : T1.lft) {
    res.lft.push_back(pair<int, int>(x.first, getParent(x.first)));
  }
  for (auto x : T2.lft) {
    if (res.lft.size() == K) break;
    res.lft.push_back(pair<int, int>(x.first, getParent(x.first)));
  }
  for (auto x : T2.rgt) {
    res.rgt.push_back(pair<int, int>(x.first, getParent(x.first)));
  }
  for (auto x : T1.rgt) {
    if (res.rgt.size() == K) break;
    res.rgt.push_back(pair<int, int>(x.first, getParent(x.first)));
  }
  for (int i = 0; i < temp.size(); i++) {
    pr[temp[i]] = 0;
  }
  return res;
}
void build(int k, int l, int r) {
  if (l == r) {
    T[k].numComp = 1;
    T[k].lft.push_back(pair<int, int>(l, l));
    T[k].rgt.push_back(pair<int, int>(l, l));
    return;
  }
  int mid = (l + r) / 2;
  build(2 * k, l, mid);
  build(2 * k + 1, mid + 1, r);
  T[k] = joinNode(T[2 * k], T[2 * k + 1], l, r);
}
Node get(int k, int l, int r, int u, int v) {
  if (r < u || l > v) return dft;
  if (u <= l && r <= v) return T[k];
  int mid = (l + r) / 2;
  Node T1 = get(2 * k, l, mid, u, v);
  Node T2 = get(2 * k + 1, mid + 1, r, u, v);
  return joinNode(T1, T2, l, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> K >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (u > v) swap(u, v);
    a[u].push_back(v);
  }
  build(1, 1, n);
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    Node res = get(1, 1, n, l, r);
    cout << res.numComp << "\n";
  }
}
