#include <bits/stdc++.h>
struct edge {
  size_t v;
  size_t id;
};
using graph = std::vector<std::vector<edge>>;
void solve(const graph& gr, std::vector<size_t>& gens, size_t gen) {
  size_t l, r;
  std::cin >> l >> r;
  l -= 1;
  r -= 1;
  size_t ccs = 0;
  std::queue<size_t> q;
  for (size_t i = 0; i < gr.size(); ++i) {
    if (gens[i] == gen) {
      continue;
    }
    ccs += 1;
    q.push(i);
    gens[i] = gen;
    while (!q.empty()) {
      size_t u = q.front();
      q.pop();
      for (auto [v, id] : gr[u]) {
        if (l <= id && id <= r) {
          continue;
        }
        if (gens[v] == gen) {
          continue;
        }
        gens[v] = gen;
        q.push(v);
      }
    }
  }
  std::cout << ccs << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n, m;
  std::cin >> n >> m;
  graph gr(n);
  for (size_t i = 0; i < m; ++i) {
    size_t x, y;
    std::cin >> x >> y;
    x -= 1;
    y -= 1;
    gr[x].push_back({y, i});
    gr[y].push_back({x, i});
  }
  size_t k;
  std::cin >> k;
  std::vector<size_t> gens(n);
  for (size_t q = 1; q <= k; ++q) {
    solve(gr, gens, q);
  }
}
