#include <bits/stdc++.h>
using namespace std;
int n, s, e;
bool vis[510];
vector<pair<int, int> > g[510];
void dfs(int p) {
  vis[p] = true;
  for (int i = 0; i < g[p].size(); i++) {
    pair<int, int> u = g[p][i];
    if ((u.second > e || u.second < s) && vis[u.first] == false) dfs(u.first);
  }
}
int main() {
  int m, i;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(make_pair(y, i));
    g[y].push_back(make_pair(x, i));
  }
  int k;
  cin >> k;
  while (k--) {
    for (i = 1; i <= n; i++) vis[i] = false;
    int ans = 0;
    cin >> s >> e;
    for (i = 1; i <= n; i++) {
      if (!vis[i]) {
        dfs(i);
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
