#include <bits/stdc++.h>
using namespace std;
int n, m, q, x, y;
int u[505];
vector<pair<int, int> > e[505];
void ope(int p) {
  u[p] = 1;
  for (int i = 0; i < e[p].size(); i++) {
    if ((e[p][i].second < x || e[p][i].second > y) && (!u[e[p][i].first]))
      ope(e[p][i].first);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    e[x].push_back(make_pair(y, i));
    e[y].push_back(make_pair(x, i));
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &x, &y);
    memset(u, 0, sizeof(u));
    int ans = 0;
    for (int j = 1; j <= n; j++)
      if (!u[j]) ope(j), ans++;
    printf("%d\n", ans);
  }
  return 0;
}
