#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
bool mrk[maxn];
vector<int> aj[maxn], ind[maxn];
int n, m, l, r;
void dfs(int v) {
  mrk[v] = true;
  for (int i = 0; i < (int)(aj[v]).size(); i++) {
    int u = aj[v][i];
    if ((ind[v][i] > r or ind[v][i] < l) and !mrk[u]) dfs(u);
  }
  return;
}
int32_t main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    aj[u].push_back(v);
    aj[v].push_back(u);
    ind[u].push_back(i);
    ind[v].push_back(i);
  }
  int K;
  scanf("%d", &K);
  while (K--) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (!mrk[i]) {
        ans++;
        dfs(i);
      }
    }
    printf("%d\n", ans);
    memset(mrk, 0, n);
  }
  return false;
}
