#include <bits/stdc++.h>
using namespace std;
int l, r;
bool mark[505];
vector<pair<int, int> > ad[505];
void dfs(int v) {
  mark[v] = true;
  for (auto u : ad[v]) {
    if ((u.second < l || u.second > r) && !mark[u.first]) dfs(u.first);
  }
  return;
}
int main() {
  int n, m, k, ans, u, v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    ad[u].push_back({v, i + 1});
    ad[v].push_back({u, i + 1});
  }
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    ans = 0;
    scanf("%d%d", &l, &r);
    for (int j = 1; j <= n; j++) {
      if (!mark[j]) {
        dfs(j);
        ans++;
      }
    }
    printf("%d\n", ans);
    memset(mark, 0, sizeof mark);
  }
  return 0;
}
