#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int K = 6;
struct node {
  int l, r, cnt, cmp[2][K];
  node() {
    l = r = cnt = 0;
    memset(cmp, 0, sizeof cmp);
  }
};
int par[30], sz[30], tmp[30], n, k;
vector<int> adj[N];
node seg[4 * N], nul;
int getPar(int v) { return par[v] == v ? v : par[v] = getPar(par[v]); }
bool merge(int u, int v) {
  u = getPar(u);
  v = getPar(v);
  if (u == v) return false;
  if (sz[v] < sz[u]) swap(u, v);
  par[u] = v;
  sz[v] += sz[u];
  return true;
}
node merge(node a, node b) {
  if (a.cnt == 0) return b;
  if (b.cnt == 0) return a;
  node c;
  c.l = a.l;
  c.r = b.r;
  c.cnt = a.cnt + b.cnt;
  int mid = b.l;
  for (int i = 0; i < 30; i++) par[i] = i, sz[i] = 1, tmp[i] = 0;
  for (int v = mid; v < min(c.r, mid + k + 1); v++)
    for (int u : adj[v])
      if (c.l <= u && u < mid &&
          merge(a.cmp[1][mid - u - 1], b.cmp[0][v - mid] + 15))
        c.cnt--;
  int lst = 1;
  for (int i = 0; i < min(k + 1, c.r - c.l); i++) {
    int v = (i < a.r - a.l ? getPar(a.cmp[0][i])
                           : getPar(b.cmp[0][i - (a.r - a.l)] + 15));
    c.cmp[0][i] = tmp[v] = (tmp[v] ? tmp[v] : lst++);
  }
  for (int i = 0; i < min(k + 1, c.r - c.l); i++) {
    int v = (i < b.r - b.l ? getPar(b.cmp[1][i] + 15)
                           : getPar(a.cmp[1][i - (b.r - b.l)]));
    c.cmp[1][i] = tmp[v] = (tmp[v] ? tmp[v] : lst++);
  }
  return c;
}
void build(int l = 1, int r = n + 1, int id = 1) {
  if (r - l == 1) {
    seg[id].l = l;
    seg[id].r = r;
    seg[id].cnt = seg[id].cmp[0][0] = seg[id].cmp[1][0] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, (id << 1));
  build(mid, r, (id << 1 | 1));
  seg[id] = merge(seg[(id << 1)], seg[(id << 1 | 1)]);
}
node get(int l, int r, int s = 1, int e = n + 1, int id = 1) {
  if (e <= l || r <= s) return nul;
  if (l <= s && e <= r) return seg[id];
  int mid = (s + e) >> 1;
  return merge(get(l, r, s, mid, (id << 1)), get(l, r, mid, e, (id << 1 | 1)));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> k >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  build();
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << get(l, r + 1).cnt << '\n';
  }
  return 0;
}
