#include <bits/stdc++.h>
using namespace std;
int l, r;
bool mark[502];
vector<pair<int, int> > adj[502];
void dfs(int v) {
  mark[v] = 1;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    if ((adj[v][i].second > r || adj[v][i].second < l) &&
        !mark[adj[v][i].first])
      dfs(adj[v][i].first);
  }
  return;
}
int main() {
  int u, v, q, n, m, c;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(make_pair(v, i)), adj[v].push_back(make_pair(u, i));
  }
  scanf("%d", &q);
  for (int j = 0; j < q; j++) {
    memset(mark, 0, sizeof(mark));
    scanf("%d%d", &l, &r);
    c = 0;
    for (int i = 1; i <= n; i++)
      if (!mark[i]) c++, dfs(i);
    printf("%d\n", c);
  }
  return 0;
}
