#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1073741824;
const int M = INF;
const double RRR = 180.0 / PI;
vector<vector<pair<int, int> > > g;
vector<int> used;
void dfs(int v, int l, int r) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i].second >= l && g[v][i].second <= r) {
      continue;
    }
    int to = g[v][i].first;
    if (!used[to]) {
      dfs(to, l, r);
    }
  }
}
int main() {
  double TIME_START = clock();
  int n, m;
  cin >> n >> m;
  used.resize(n);
  g.resize(n);
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  int k;
  cin >> k;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    l--;
    r--;
    int col = 0;
    used.assign(n, 0);
    for (int i = 0; i < n; i++) {
      if (!used[i]) {
        col++;
        dfs(i, l, r);
      }
    }
    cout << col << endl;
  }
  fprintf(stderr, "\n\n%.15lf\n\n",
          (double)(clock() - TIME_START) / CLOCKS_PER_SEC);
  return 0;
}
