12 12
5 1
5 11
1 11
8 11
8 9
5 12
6 9
7 11
9 3
9 10
4 12
10 2
78
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
5 5
5 6
5 7
5 8
5 9
5 10
5 11
5 12
6 6
6 7
6 8
6 9
6 10
6 11
6 12
7 7
7 8
7 9
7 10
7 11
7 12
8 8
8 9
8 10
8 11
8 12
9 9
9 10
9 11
9 12
10 10
10 11
10 12
11 11
11 12
12 12

1
3
6
10
15
21
28
36
45
55
65
76
1
3
6
10
15
21
28
36
45
55
66
1
3
6
10
15
21
28
36
45
55
1
3
6
10
15
21
28
36
45
1
3
6
10
15
21
28
36
1
3
6
10
15
21
28
1
3
6
10
15
21
1
3
6
10
15
1
3
6
10
1
3
6
1
3
1

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300100;
long long sum[4 * MAXN];
long long lazy[4 * MAXN];
int propagate_st(int nod, int l, int r) {
  if (lazy[nod]) {
    sum[nod] += lazy[nod] * (long long)(r - l + 1);
    if (l < r) {
      int ls = nod * 2, rs = ls + 1;
      lazy[ls] += lazy[nod];
      lazy[rs] += lazy[nod];
    }
    lazy[nod] = 0;
  }
}
void update_st(int nod, int l, int r, int lq, int rq, long long upd) {
  propagate_st(nod, l, r);
  if (l > rq || r < lq) {
    return;
  }
  if (lq <= l && r <= rq) {
    lazy[nod] += upd;
    propagate_st(nod, l, r);
    return;
  }
  int ls = nod * 2, rs = ls + 1;
  int mid = (l + r) / 2;
  update_st(ls, l, mid, lq, rq, upd);
  update_st(rs, mid + 1, r, lq, rq, upd);
  sum[nod] = sum[ls] + sum[rs];
}
long long query_st(int nod, int l, int r, int lq, int rq) {
  if (l > rq || r < lq) {
    return 0;
  }
  if (lq <= l && r <= rq) {
    return sum[nod];
  }
  int ls = nod * 2, rs = ls + 1;
  int mid = (l + r) / 2;
  return query_st(ls, l, mid, lq, rq) + query_st(rs, mid + 1, r, lq, rq);
}
int n, m;
vector<int> ady[MAXN];
set<int> g[MAXN];
bool ok[MAXN];
int col[MAXN];
map<int, int> cc;
int color;
int comp;
void paint(int u, int p, int color) {
  col[u] = color;
  for (auto v : g[u]) {
    if (v != p) {
      paint(v, u, color);
    }
  }
}
void add_node(int u) {
  ok[u] = true;
  col[u] = ++color;
  cc[color] = 1;
  comp++;
}
bool add_edge(int u, int v) {
  if (col[u] == col[v]) {
    return false;
  }
  if (cc[col[u]] > cc[col[v]]) {
    swap(u, v);
  }
  cc[col[v]] += cc[col[u]];
  paint(u, 0, col[v]);
  g[u].insert(v);
  g[v].insert(u);
  comp--;
  return true;
}
int mk[MAXN], mark;
set<int>::iterator pos[MAXN];
int get_next(queue<int> &q) {
  while (!q.empty()) {
    int u = q.front();
    if (pos[u] == g[u].end()) {
      q.pop();
      continue;
    }
    int v = *pos[u];
    pos[u]++;
    if (mk[v] != mark) {
      mk[v] = mark;
      pos[v] = g[v].begin();
      q.push(v);
      return v;
    }
  }
  return 0;
}
void remove_edge(int u, int v) {
  mark++;
  mk[u] = mk[v] = mark;
  g[u].erase(v);
  g[v].erase(u);
  queue<int> q1, q2;
  q1.push(u);
  pos[u] = g[u].begin();
  q2.push(v);
  pos[v] = g[v].begin();
  int sz1 = 1, sz2 = 1;
  while (sz1 == sz2) {
    int v1 = get_next(q1);
    if (v1 != 0) {
      sz1++;
    }
    int v2 = get_next(q2);
    if (v2 != 0) {
      sz2++;
    }
    if (!v1 && !v2) {
      break;
    }
  }
  if (sz1 > sz2) {
    swap(u, v);
    swap(sz1, sz2);
  }
  cc[col[v]] -= sz1;
  paint(u, 0, ++color);
  cc[col[u]] = sz1;
  comp++;
}
void remove_node(int u) {
  ok[u] = false;
  comp--;
}
vector<pair<pair<int, int>, int> > qs;
long long sol[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    ady[u].push_back(v);
    ady[v].push_back(u);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    qs.push_back(pair<pair<int, int>, int>(pair<int, int>(r, l), i));
  }
  sort(qs.begin(), qs.end());
  int L = 1;
  int ind = 0;
  for (int u = 1; u <= n && ind < qs.size(); u++) {
    add_node(u);
    for (int i = 0; i < ady[u].size(); i++) {
      int v = ady[u][i];
      while (ok[v] && !add_edge(u, v)) {
        vector<int> tmp;
        for (auto w : g[L]) {
          tmp.push_back(w);
        }
        for (auto w : tmp) {
          remove_edge(L, w);
        }
        remove_node(L);
        L++;
      }
    }
    update_st(1, 1, n, L, u, 1);
    while (ind < qs.size() && qs[ind].first.first <= u) {
      int l = qs[ind].first.second;
      int r = qs[ind].first.first;
      int iq = qs[ind].second;
      sol[iq] = query_st(1, 1, n, l, r);
      ind++;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << sol[i] << '\n';
  }
}
