#include <bits/stdc++.h>
using namespace std;
pair<int, int> g[510][510];
int size[510];
bool vis[510];
int n, m;
int l, r;
void dfs(int i) {
  vis[i] = true;
  for (int k = 1; k <= size[i]; k++) {
    int next = g[i][k].first;
    int edge = g[i][k].second;
    if (edge >= l && edge <= r) continue;
    if (vis[next]) continue;
    dfs(next);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  int i;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    g[x][++size[x]] = make_pair(y, i);
    g[y][++size[y]] = make_pair(x, i);
  }
  int Q;
  scanf("%d", &Q);
  int cnt;
  while (Q--) {
    scanf("%d%d", &l, &r);
    memset(vis, false, sizeof(vis));
    cnt = 0;
    for (i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
