#include <bits/stdc++.h>
using namespace std;
const int MAXn = 500 + 10;
int n, mi, q, u, v, ans, l, r;
bool m[MAXn], mm = 1;
vector<pair<int, int> > adj[MAXn];
void dfs(int v) {
  m[v] ^= 1;
  for (auto u : adj[v])
    if ((u.second > r || u.second < l) && m[u.first] != mm) dfs(u.first);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> mi;
  for (int i = 0; i < mi; ++i) {
    cin >> v >> u;
    adj[v].push_back(make_pair(u, i + 1));
    adj[u].push_back(make_pair(v, i + 1));
  }
  cin >> q;
  while (q--) {
    cin >> l >> r;
    for (int i = 1; i < n + 1; ++i)
      if (m[i] != mm) ans++, dfs(i);
    cout << ans << "\n";
    mm ^= 1;
    ans = 0;
  }
  return 0;
}
