#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[555];
int l, r;
bool vis[555];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first, id = g[u][i].second;
    if (id >= l && id <= r) continue;
    if (vis[v]) continue;
    dfs(v);
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  int k;
  scanf("%d", &k);
  while (k--) {
    scanf("%d %d", &l, &r);
    for (int i = 1; i <= n; ++i) vis[i] = 0;
    int res = 0;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        ++res;
        dfs(i);
      }
    printf("%d\n", res);
  }
}
