#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > sous[555];
int clr[555];
int ans;
int from, to;
void dfs(int v) {
  for (int i = (0); i < (sous[v].size()); ++i) {
    if (sous[v][i].second >= from && sous[v][i].second <= to) continue;
    int vv = sous[v][i].first;
    if (clr[vv] == -1) {
      clr[vv] = ans;
      dfs(vv);
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    sous[a - 1].push_back(make_pair(b - 1, i + 1));
    sous[b - 1].push_back(make_pair(a - 1, i + 1));
  }
  int k;
  scanf("%d", &k);
  for (int i = (0); i < (k); ++i) {
    int l, r;
    ans = 0;
    scanf("%d %d", &l, &r);
    from = l;
    to = r;
    for (int j = (0); j < (n); ++j) clr[j] = -1;
    for (int j = (0); j < (n); ++j)
      if (clr[j] == -1) {
        ans++;
        dfs(j);
      }
    printf("%d\n", ans);
  }
  return 0;
}
