#include <bits/stdc++.h>
using namespace std;
int n, m, k, s[520], u[505], x, y, c, q[70000];
vector<pair<int, int> > e[505];
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", &k);
  for (c = 1; c <= k; c++) {
    scanf("%d%d", &x, &y);
    int ans = 0;
    for (int j = 1; j <= n; j++) {
      if (u[j] == c) continue;
      ans++;
      int w = 1;
      q[1] = j;
      u[j] = c;
      for (int i = 1; i <= w; i++) {
        for (vector<pair<int, int> >::iterator it = e[q[i]].begin();
             it != e[q[i]].end(); it++) {
          if ((it->second < x || it->second > y)) {
            if (u[it->first] < c) q[++w] = it->first, u[it->first] = c;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
