#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
vector<int> g[500];
int n, m, k, ans, l, r, e[10000];
bool b[10000];
void dfs(int x) {
  b[x] = true;
  for (int i = 0; i < g[x].size(); i++) {
    if (l <= g[x][i] and r >= g[x][i]) continue;
    int y = e[g[x][i]] ^ x;
    if (!b[y]) dfs(y);
  }
}
int main() {
  n = read(), m = read();
  for (int i = 0; i < m; i++) {
    int x = read() - 1, y = read() - 1;
    g[x].push_back(i);
    g[y].push_back(i);
    e[i] = x ^ y;
  }
  k = read();
  for (int i = 0; i < k; i++) {
    l = read() - 1, r = read() - 1, ans = 0;
    memset(b, 0, sizeof(b));
    for (int j = 0; j < n; j++)
      if (!b[j]) ans++, dfs(j);
    printf("%d\n", ans);
  }
  return 0;
}
