#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
inline char gc() {
  static const int L = 1000;
  static char sxd[L], *sss = sxd, *ttt = sxd;
  if (sss == ttt) {
    ttt = (sss = sxd) + fread(sxd, 1, L, stdin);
    if (sss == ttt) return EOF;
  }
  return *sss++;
}
inline int read(int& x) {
  x = 0;
  char c = getchar();
  bool f = false;
  for (; !isdigit(c); c = getchar()) {
    if (c == EOF) return -1;
    if (c == '-') f = true;
  }
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return 1;
}
int i, j, n, m, k, x, y, z, a[20000], b[20000], f[20000];
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
int main() {
  read(n);
  read(m);
  for (i = 1; i <= m; i++) {
    read(a[i]);
    read(b[i]);
  }
  read(k);
  for (j = 1; j <= k; j++) {
    read(x);
    read(y);
    for (i = 1; i <= n; i++) f[i] = i;
    z = n;
    for (i = 1; i < x; i++) {
      if (find(a[i]) != find(b[i])) {
        f[f[a[i]]] = f[b[i]];
        z--;
      }
    }
    for (i = y + 1; i <= m; i++) {
      if ((find(a[i])) != (find(b[i]))) {
        f[f[a[i]]] = f[b[i]];
        z--;
      }
    }
    cout << z << endl;
  }
  return 0;
}
