#include <bits/stdc++.h>
using namespace std;
struct node {
  vector<pair<int, int> > e;
  int visited;
  node() { this->visited = -1; }
};
node t[500];
void dfs(int l, int r, int p, int flag) {
  if (t[p].visited == flag) return;
  t[p].visited = flag;
  int i, j;
  for (i = 0; i < t[p].e.size(); i++) {
    pair<int, int> &k = t[p].e[i];
    if (k.second >= l) break;
    if (t[k.first].visited != flag) dfs(l, r, k.first, flag);
  }
  for (int j = t[p].e.size() - 1; j >= i; j--) {
    pair<int, int> &k = t[p].e[j];
    if (k.second <= r) break;
    if (t[k.first].visited != flag) dfs(l, r, k.first, flag);
  }
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
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);
    a--;
    b--;
    t[a].e.push_back(make_pair(b, i));
    t[b].e.push_back(make_pair(a, i));
  }
  for (int i = 0; i < n; i++) sort(t[i].e.begin(), t[i].e.end(), cmp);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int cnt = 0;
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    for (int j = 0; j < n; j++)
      if (t[j].visited != i) {
        dfs(l, r, j, i);
        cnt++;
      }
    printf("%d\n", cnt);
  }
  return 0;
}
