#include <bits/stdc++.h>
using namespace std;
void readline(char *s) {
  int len = 0;
  char c;
  for (c = ((char)fgetc(stdin)); c != '\n';
       s[len++] = c, c = ((char)fgetc(stdin)))
    ;
  s[len] = 0;
}
void readstr(char *s) {
  int len = 0;
  char c;
  for (c = ((char)fgetc(stdin)); c != ' ' && c != '\n';
       s[len++] = c, c = ((char)fgetc(stdin)))
    ;
  s[len] = 0;
}
void printstr(const char *s) {
  int len = strlen(s);
  for (int(i) = (0); (i) <= (len - 1); i++) fputc((s[i]), stdout);
}
void to_lower(char *s, int L, int R) {
  for (int(i) = (L); (i) <= (R); i++)
    if (((s[i]) >= 'A' && (s[i]) <= 'Z')) s[i] = s[i] - 'A' + 'a';
}
void to_upper(char *s, int L, int R) {
  for (int(i) = (L); (i) <= (R); i++)
    if (((s[i]) >= 'a' && (s[i]) <= 'z')) s[i] = s[i] - 'a' + 'A';
}
long long readll() {
  char c;
  long long ans = 0, x = 1;
  for (c = ((char)fgetc(stdin)); !((c) >= '0' && (c) <= '9') && c != '-';
       c = ((char)fgetc(stdin)))
    ;
  if (c == '-') x = -1, c = ((char)fgetc(stdin));
  for (; ((c) >= '0' && (c) <= '9');
       ans = ans * 10 + c - '0', c = ((char)fgetc(stdin)))
    ;
  return ans * x;
}
void printll(long long x) {
  int a[25], cnt = 0;
  if (x == 0) {
    fputc(('0'), stdout);
    return;
  }
  if (x < 0) fputc(('-'), stdout), x = -x;
  for (; x; a[cnt++] = x - x / 10 * 10, x /= 10)
    ;
  for (int(i) = (cnt - 1); (i) >= (0); i--) fputc((a[i] + '0'), stdout);
}
struct dsu {
  int n, par[505], size[505];
  void init(int N) {
    n = N;
    for (int i = 1; i <= n; i++) {
      size[i] = 1;
      par[i] = i;
    }
  }
  int find(int x) { return (x == par[x] ? x : par[x] = find(par[x])); }
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (size[x] > size[y]) swap(x, y);
    par[x] = y;
    if (size[x] == size[y]) size[y]++;
  }
} DSU;
int n, m;
struct Pair {
  int x, y;
  Pair(int a = 0, int b = 0) {
    x = a;
    y = b;
  }
} edge[10005];
int main() {
  n = ((int)readll());
  m = ((int)readll());
  for (int(i) = (1); (i) <= (m); i++) {
    int x = ((int)readll()), y = ((int)readll());
    edge[i] = Pair(x, y);
  }
  int q = ((int)readll());
  while (q--) {
    int l = ((int)readll()), r = ((int)readll());
    DSU.init(n);
    for (int(i) = (1); (i) <= (l - 1); i++) DSU.merge(edge[i].x, edge[i].y);
    for (int(i) = (r + 1); (i) <= (m); i++) DSU.merge(edge[i].x, edge[i].y);
    int ans = 0;
    for (int(i) = (1); (i) <= (n); i++)
      if (DSU.find(i) == i) ans++;
    printll((long long)(ans));
    fputc(('\n'), stdout);
  }
  return 0;
}
