#include <bits/stdc++.h>
using namespace std;
int n, m, X, Y;
bool used[555];
vector<pair<int, int> > e[555];
void dfs(int u) {
  used[u] = true;
  for (__typeof(e[u].begin()) it = e[u].begin(); it != e[u].end(); ++it)
    if ((*it).second < X || (*it).second > Y) {
      if (!used[(*it).first]) dfs((*it).first);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    e[x].push_back(make_pair(y, i));
    e[y].push_back(make_pair(x, i));
  }
  int k;
  scanf("%d", &k);
  while (k--) {
    scanf("%d%d", &X, &Y);
    --X, --Y;
    memset(used, 0, sizeof(used));
    int cnt = 0;
    for (int i = 0; i < n; ++i)
      if (!used[i]) {
        ++cnt;
        dfs(i);
      }
    printf("%d\n", cnt);
  }
  return 0;
}
