#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 17;
struct union_find {
  vector<int> par;
  int ncomp;
  union_find(int sz = 0) {
    for (int i = 0; i < sz; i++) {
      par.push_back(i);
    }
    ncomp = sz;
  }
  int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
  bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }
    ncomp--;
    par[x] = y;
    return true;
  }
};
int N, M, Q;
vector<int> adj[MAXN];
bool has[MAXN][6];
union_find ufseg[2 * MAXN];
int L[MAXN], R[MAXN];
void update(int x, int y, int cur = 1, int lt = 0, int rt = MAXN) {
  if (lt <= x && x < rt && lt <= y && y < rt) {
    ufseg[cur].merge(x - lt, y - lt);
    int mid = (lt + rt) / 2;
    update(x, y, 2 * cur, lt, mid);
    update(x, y, 2 * cur + 1, mid, rt);
  }
}
union_find ufans(MAXN);
vector<pair<int, int>> nedge;
map<int, vector<int>> comps;
int query(int a, int b, int cur = 1, int lt = 0, int rt = MAXN) {
  if (rt <= a || b <= lt) {
    return 0;
  }
  if (a <= lt && rt <= b) {
    for (int i = rt - 1; i >= lt && i >= rt - 5; i--) {
      for (int j = 1; j <= 5; j++) {
        if (has[i][j] && a <= i + j && i + j < b) {
          nedge.push_back({i, i + j});
        }
      }
      comps[lt + ufseg[cur].find(i - lt)].push_back(i);
    }
    for (int i = lt; i < lt + 5 && i < rt; i++) {
      comps[lt + ufseg[cur].find(i - lt)].push_back(i);
    }
    return ufseg[cur].ncomp;
  }
  int mid = (lt + rt) / 2;
  return query(a, b, 2 * cur, lt, mid) + query(a, b, 2 * cur + 1, mid, rt);
}
int main() {
  scanf("%d %*d %d", &N, &M);
  for (int i = 0; i < MAXN; i++) {
    ufseg[i + MAXN] = union_find(1);
  }
  for (int i = MAXN - 1; i; i--) {
    ufseg[i] =
        union_find(ufseg[2 * i].par.size() + ufseg[2 * i + 1].par.size());
  }
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (x > y) {
      swap(x, y);
    }
    update(x, y);
    has[x][y - x] = true;
  }
  scanf("%d", &Q);
  for (int qi = 0; qi < Q; qi++) {
    int lt, rt;
    scanf("%d %d", &lt, &rt);
    rt++;
    int ans = query(lt, rt);
    for (auto it : comps) {
      vector<int> v = it.second;
      for (int i : v) {
        ufans.merge(i, v[0]);
      }
    }
    for (pair<int, int> p : nedge) {
      ans -= ufans.merge(p.first, p.second);
    }
    printf("%d\n", ans);
    for (auto it : comps) {
      vector<int> v = it.second;
      for (int i : v) {
        ufans.par[i] = i;
      }
    }
    nedge.clear();
    comps.clear();
  }
}
