#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int uf[N];
int sp;
int num;
pair<int, int> undostack[5050505];
void inituf() {
  memset(uf, -1, sizeof(uf));
  sp = 0;
  num = 0;
}
int uffind(int x) {
  while (uf[x] >= 0) x = uf[x];
  return x;
}
void ufunion(int x, int y) {
  x = uffind(x);
  y = uffind(y);
  if (x == y) return;
  undostack[sp++] = make_pair(x, uf[x]);
  undostack[sp++] = make_pair(y, uf[y]);
  if (uf[x] > uf[y]) swap(x, y);
  uf[x] += uf[y];
  uf[y] = x;
  num--;
}
void ufundo() {
  assert(sp > 0);
  auto p = undostack[--sp];
  auto q = undostack[--sp];
  uf[p.first] = p.second;
  uf[q.first] = q.second;
  num++;
}
int main() {
  inituf();
  const int S = 567;
  int n, K, m;
  cin >> n >> K >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int q;
  cin >> q;
  vector<int> ans(q);
  vector<int> l(q), r(q);
  auto add = [&](int l, int r, int ll, int rr) {
    for (int i = l; i < r; i++) {
      for (int j : g[i])
        if (ll <= j && j < rr) {
          ufunion(i, j);
        }
    }
  };
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l[i], &r[i]);
    l[i]--;
    if (l[i] / S == r[i] / S) {
      add(l[i], r[i], l[i], r[i]);
      ans[i] = num + (r[i] - l[i]);
      while (sp > 0) ufundo();
    }
  }
  vector<int> ord(q);
  for (int i = 0; i < q; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    if (l[i] / S != l[j] / S) return l[i] < l[j];
    return r[i] < r[j];
  });
  int prev = -1;
  int rr = 0;
  for (int id : ord) {
    if (l[id] / S == r[id] / S) continue;
    int mid = l[id] / S * S + S;
    if (mid != prev) {
      inituf();
      rr = mid;
    }
    prev = mid;
    add(rr, r[id], mid, r[id]);
    rr = r[id];
    int spsp = sp;
    add(l[id], mid, l[id], r[id]);
    ans[id] = num + (r[id] - l[id]);
    while (sp > spsp) ufundo();
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", ans[i]);
  }
}
