#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
const int N = 100005;
const int K = 5;
int tree[N * 4], pre[N * 4][K], suf[N * 4][K];
int tp[N], trans[N], tpre[100], tsuf[100], pa[N];
vector<int> ds[N], adj[N];
void dfs(int u) {
  ans--;
  for (auto &v : ds[u]) {
    if (tp[v] > 0) continue;
    tp[v] = tp[u];
    dfs(v);
  }
}
int getpa(int u) { return (pa[u] < 0) ? u : (pa[u] = getpa(pa[u])); }
int combine(int *fpre, int *fsuf, int *left_pre, int *left_suf, int *right_pre,
            int *right_suf, int l, int m, int r) {
  int l1 = l, l2 = m;
  int r1 = m - 1, r2 = r;
  for (int i = 0; i < k && l1 + i <= r1; i++) {
    pa[l1 + i] = left_pre[i];
    pa[r1 - i] = left_suf[i];
  }
  for (int i = 0; i < k && l2 + i <= r2; i++) {
    pa[l2 + i] = right_pre[i];
    pa[r2 - i] = right_suf[i];
  }
  int ans = 0;
  for (int i = 0; i < k && l1 <= r1 - i; i++)
    for (auto &x : adj[r1 - i]) {
      if (x < l2 || x > r2) continue;
      int u = getpa(r1 - i);
      int v = getpa(x);
      if (u == v) continue;
      ans--;
      if (pa[u] > pa[v]) swap(u, v);
      pa[u] += pa[v];
      pa[v] = u;
    }
  for (int i = 0; i < k && l1 + i <= r1; i++) {
    trans[getpa(l1 + i)] = trans[getpa(r1 - i)] = 0;
  }
  for (int i = 0; i < k && l2 + i <= r2; i++) {
    trans[getpa(l2 + i)] = trans[getpa(r2 - i)] = 0;
  }
  for (int i = 0; i < k && l1 + i <= r2; i++) {
    fpre[i] = pa[l1 + i];
    if ((fpre[i] >= l1 && fpre[i] <= l1 + k - 1) ||
        (fpre[i] >= r2 - k + 1 && fpre[i] <= r2)) {
    } else {
      if (fpre[i] < 0) {
        fpre[i] = -1;
      } else {
        if (trans[fpre[i]] == 0) {
          trans[fpre[i]] = l1 + i;
          fpre[i] = -1;
        } else {
          fpre[i] = trans[fpre[i]];
        }
      }
    }
    fsuf[i] = pa[r2 - i];
    if ((fsuf[i] >= l1 && fsuf[i] <= l1 + k - 1) ||
        (fsuf[i] >= r2 - k + 1 && fsuf[i] <= r2)) {
    } else {
      if (fsuf[i] < 0) {
        fsuf[i] = -1;
      } else {
        if (trans[fsuf[i]] == 0) {
          trans[fsuf[i]] = r2 - i;
          fsuf[i] = -1;
        } else {
          fsuf[i] = trans[fsuf[i]];
        }
      }
    }
  }
  return ans;
}
void combine_node(int nd, int l, int r) {
  int cc = nd << 1;
  tree[nd] = tree[cc] + tree[cc ^ 1] +
             combine(pre[nd], suf[nd], pre[cc], suf[cc], pre[cc ^ 1],
                     suf[cc ^ 1], l, ((l + r) >> 1) + 1, r);
}
void build(int nd, int l, int r) {
  if (l == r) {
    tree[nd] = 1;
    pre[nd][0] = -1;
    suf[nd][0] = -1;
    return;
  }
  int m = (l + r) >> 1;
  int cc = nd << 1;
  build(cc, l, m);
  build(cc ^ 1, m + 1, r);
  combine_node(nd, l, r);
}
int query(int nd, int l, int r, int tr, int ph, int *tpre, int *tsuf) {
  if (l > ph || r < tr) return 0;
  if (tr <= l && r <= ph) {
    if (tr == l) {
      for (int i = 0; i < k && l + i <= r; i++) tpre[i] = pre[nd][i];
      for (int i = 0; i < k && r - i >= l; i++) tsuf[i] = suf[nd][i];
      return tree[nd];
    } else
      return tree[nd] +
             combine(tpre, tsuf, tpre, tsuf, pre[nd], suf[nd], tr, l, r);
  }
  int m = (l + r) >> 1;
  int cc = nd << 1;
  int tmp = query(cc, l, m, tr, ph, tpre, tsuf);
  return tmp + query(cc ^ 1, m + 1, r, tr, ph, tpre, tsuf);
}
int main() {
  scanf("%d%d", &n, &k);
  int m;
  scanf("%d", &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (u > v) swap(u, v);
    adj[u].push_back(v);
  }
  int q;
  scanf("%d", &q);
  build(1, 1, n);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(1, 1, n, l, r, tpre, tsuf));
  }
}
