#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long LINF = 4000000000000000000ll;
void prepare() {}
int n, m, k;
vector<pair<int, int> > e[505];
bool used[505];
int color, ll, rr;
void dfs(int x) {
  used[x] = true;
  for (int i = 0; i < e[x].size(); i++) {
    pair<int, int> q = e[x][i];
    if (q.first >= ll && q.first <= rr) continue;
    if (!used[q.second]) dfs(q.second);
  }
}
bool solve() {
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    e[a].push_back(make_pair(i, b));
    e[b].push_back(make_pair(i, a));
  }
  for (int i = 0; i < n; i++) sort(e[i].begin(), e[i].end());
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    ll = a;
    rr = b;
    memset(used, 0, sizeof(used));
    color = 0;
    for (int j = 0; j < n; j++)
      if (!used[j]) {
        dfs(j);
        color++;
      }
    printf("%d\n", color);
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
