#include <bits/stdc++.h>
using namespace std;
int n, m, k, l, u;
vector<pair<int, int> > g[500];
bool vis[500];
void DFS(int x) {
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); ++i) {
    if (g[x][i].second >= l && g[x][i].second <= u) continue;
    if (!vis[g[x][i].first]) DFS(g[x][i].first);
  }
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(make_pair(b, i));
    g[b].push_back(make_pair(a, i));
  }
  scanf("%d", &k);
  while (k--) {
    int ans = 0;
    scanf("%d%d", &l, &u);
    --l;
    --u;
    for (int i = 0; i < n; ++i) vis[i] = 0;
    for (int i = 0; i < n; ++i)
      if (!vis[i]) {
        ++ans;
        DFS(i);
      }
    printf("%d\n", ans);
  }
  return 0;
}
