#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
vector<pair<int, int> > v[555];
bool vis[555];
inline void go(int s, int l, int r) {
  vis[s] = true;
  for (int i = 0, maxi = (int)(v[s]).size(); i < maxi && v[s][i].second < l;
       i++) {
    if (!vis[v[s][i].first]) go(v[s][i].first, l, r);
  }
  for (int i = (int)(v[s]).size() - 1; i >= 0 && v[s][i].second > r; i--) {
    if (!vis[v[s][i].first]) go(v[s][i].first, l, r);
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(make_pair(y, i));
    v[y].push_back(make_pair(x, i));
  }
  int k;
  scanf("%d", &k);
  for (int test = 0; test < k; test++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int i = 0; i < 555; i++) vis[i] = false;
    int res = 0;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) go(i, l, r), res++;
    }
    printf("%d\n", res);
  }
  return 0;
}
