#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1, maxh = 18;
int n, k, seg[maxn][maxh], par[maxn * maxh], sz[maxn * maxh], mx, ans;
int cnt[4 * maxn], indq[maxn], szr;
bool mark[maxn * maxh];
vector<int> g[maxn];
pair<int, pair<int, int> > rep[maxn * maxh];
deque<int> dq;
int root(int v, bool ch) {
  if (par[v] == v) return v;
  int u = root(par[v], ch);
  if (!ch && !mark[v]) {
    mark[v] = true;
    rep[szr++] = pair<int, pair<int, int> >(v, pair<int, int>(sz[v], par[v]));
  }
  par[v] = u;
  return u;
}
int merge(int v, int u, bool ch = true) {
  v = root(v, ch);
  u = root(u, ch);
  if (sz[v] > sz[u]) swap(v, u);
  if (v == u) return 0;
  if (!ch && !mark[v]) {
    mark[v] = true;
    rep[szr++] = pair<int, pair<int, int> >(v, pair<int, int>(sz[v], par[v]));
  }
  if (!ch && !mark[u]) {
    mark[u] = true;
    rep[szr++] = pair<int, pair<int, int> >(u, pair<int, int>(sz[u], par[u]));
  }
  par[v] = u;
  sz[u] += sz[v];
  return 1;
}
void build(int s = 0, int e = n, int h = 0, int id = 1) {
  int it = h * n + s;
  if (e - s == 1) {
    cnt[id] = 1;
    seg[s][h] = it;
    par[it] = it;
    indq[s] = -1;
    return;
  }
  int mid = (s + e) / 2;
  build(s, mid, h + 1, 2 * id);
  build(mid, e, h + 1, 2 * id + 1);
  for (int i = s; i < e; i++) {
    seg[i][h] = it;
    par[it] = it;
    sz[it] = 1;
    it++;
  }
  cnt[id] = e - s;
  for (int i = s; i < e; i++)
    for (auto j : g[i])
      if (j >= s && j < e) cnt[id] -= merge(seg[i][h], seg[j][h]);
}
void get(int l, int r, int s = 0, int e = n, int h = 0, int id = 1) {
  if (r <= s || e <= l) return;
  if (l <= s && e <= r) {
    ans += cnt[id];
    for (int i = s; i < e && i < s + k; i++)
      for (auto j : g[i])
        if (indq[j] >= 0) ans -= merge(indq[j], seg[i][h], false);
    for (int i = max(e - k - 1, s); i < e; i++) {
      dq.push_front(seg[i][h]);
      indq[seg[i][h] % n] = seg[i][h];
    }
    while ((int)dq.size() > k) {
      indq[dq.back() % n] = -1;
      dq.pop_back();
    }
    return;
  }
  int mid = (s + e) / 2;
  get(l, r, s, mid, h + 1, 2 * id);
  get(l, r, mid, e, h + 1, 2 * id + 1);
}
int main() {
  scanf("%d%d", &n, &k);
  int m;
  scanf("%d", &m);
  while (m--) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    if (v < u) swap(v, u);
    g[v].push_back(u);
  }
  build();
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    ans = 0;
    while ((int)dq.size()) {
      indq[dq.back() % n] = -1;
      dq.pop_back();
    }
    get(l, r);
    printf("%d\n", ans);
    while (szr) {
      pair<int, pair<int, int> > i = rep[--szr];
      sz[i.first] = i.second.first;
      par[i.first] = i.second.second;
      mark[i.first] = false;
    }
  }
}
