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;
struct eg {
  int u, v, nx;
} gp[600010];
int n, m, q, cnt, hd[300010];
inline void psh(int u, int v) {
  ++cnt;
  gp[cnt].u = u, gp[cnt].v = v, gp[cnt].nx = hd[u], hd[u] = cnt;
};
int te[1200010][2];
void _upd(int l, int r, int d, int x, int ni) {
  int m = (l + r) >> 1;
  if (l == r)
    te[ni][0] = te[ni][1] = x;
  else {
    if (d <= m)
      _upd(l, m, d, x, ni << 1);
    else
      _upd(m + 1, r, d, x, ni << 1 | 1);
    te[ni][0] = max(te[ni << 1][0], te[ni << 1 | 1][0]);
    te[ni][1] = min(te[ni << 1][1], te[ni << 1 | 1][1]);
  }
};
pair<int, int> _qry(int l, int r, int a, int b, int ni) {
  int m = (l + r) >> 1;
  pair<int, int> t(-1, 1000000);
  if (l == a && r == b)
    return pair<int, int>(te[ni][0], te[ni][1]);
  else {
    if (b <= m)
      return _qry(l, m, a, b, ni << 1);
    else if (a > m)
      return _qry(m + 1, r, a, b, ni << 1 | 1);
    else {
      pair<int, int> z = _qry(l, m, a, m, ni << 1);
      pair<int, int> x = _qry(m + 1, r, m + 1, b, ni << 1 | 1);
      t.first = max(z.first, x.first);
      t.second = min(z.second, x.second);
      return t;
    }
  }
};
long long _te[1200010], _sm[1200010];
inline void __pshd(int l, int r, int ni) {
  int m = (l + r) >> 1;
  _te[ni << 1] += (long long)(m - l + 1) * _sm[ni];
  _te[ni << 1 | 1] += (long long)(r - m) * _sm[ni];
  _sm[ni << 1] += _sm[ni], _sm[ni << 1 | 1] += _sm[ni];
  _sm[ni] = 0;
};
void __upd(int l, int r, int a, int b, long long x, int ni) {
  int m = (l + r) >> 1;
  if (l == a && r == b)
    _sm[ni] += x, _te[ni] += (long long)(r - l + 1) * x;
  else {
    if (_sm[ni]) __pshd(l, r, ni);
    if (b <= m)
      __upd(l, m, a, b, x, ni << 1);
    else if (a > m)
      __upd(m + 1, r, a, b, x, ni << 1 | 1);
    else
      __upd(l, m, a, m, x, ni << 1), __upd(m + 1, r, m + 1, b, x, ni << 1 | 1);
    _te[ni] = _te[ni << 1 | 1] + _te[ni << 1];
  }
};
long long __qry(int l, int r, int a, int b, int ni) {
  int m = (l + r) >> 1;
  if (l == a && r == b)
    return _te[ni];
  else {
    if (_sm[ni]) __pshd(l, r, ni);
    if (b <= m)
      return __qry(l, m, a, b, ni << 1);
    else if (a > m)
      return __qry(m + 1, r, a, b, ni << 1 | 1);
    else
      return __qry(l, m, a, m, ni << 1) +
             __qry(m + 1, r, m + 1, b, ni << 1 | 1);
  }
};
struct bi {
  int a, b;
  bi(int _a = 0, int _b = 0) : a(_a), b(_b){};
} br[300010];
int bn, dep[300010];
bool bd[300010];
bool bimp(const bi& a, const bi& b) { return a.a < b.a; };
void dfs(int v, int d) {
  int i, j;
  bd[v] = 1, dep[v] = d;
  _upd(1, n, d, v, 1);
  for (i = hd[v]; i; i = gp[i].nx)
    if (gp[i].v > 0) {
      if (!bd[gp[i].v]) {
        gp[i & 1 ? i + 1 : i - 1].v = -1;
        dfs(gp[i].v, d + 1);
      } else {
        pair<int, int> t = _qry(1, n, dep[gp[i].v], dep[v], 1);
        br[++bn] = bi(t.second, t.first);
        gp[i & 1 ? i + 1 : i - 1].v = -1;
      }
    }
};
int _mi[300010], _mx[300010];
void _cl() {
  int i, j, k;
  sort(br + 1, br + bn + 1, bimp);
  for (_mi[bn] = br[bn].b, i = bn - 1; i > 0; --i)
    _mi[i] = min(_mi[i + 1], br[i].b);
  for (i = 1, j = 1; i <= n; ++i) {
    for (; j <= bn && br[j].a < i; ++j)
      ;
    _mx[i] = j <= bn ? _mi[j] : n + 1;
  }
};
struct qrt {
  int l, r;
  long long rs;
  int id;
} qr[300010];
bool qrmp(const qrt& a, const qrt& b) { return a.l < b.l; };
bool _qrmp(const qrt& a, const qrt& b) { return a.id < b.id; };
void __cl() {
  int i, j, k;
  sort(qr, qr + q, qrmp);
  for (memset(_te, 0, sizeof(_te)), memset(_sm, 0, sizeof(_sm)), i = 1; i <= n;
       ++i)
    if (_mx[i] > i) __upd(1, n, i, _mx[i] - 1, 1, 1);
  for (i = 0, j = 1; i < q; ++i) {
    for (; j < qr[i].l; ++j)
      if (_mx[j] > j) __upd(1, n, j, _mx[j] - 1, -1, 1);
    qr[i].rs = __qry(1, n, qr[i].l, qr[i].r, 1);
  }
  sort(qr, qr + q, _qrmp);
};
void cl() {
  int i, j, k, a, b;
  scanf("%d %d", &n, &m);
  for (memset(hd, 0, sizeof(hd)), cnt = 0, i = 0; i < m; ++i) {
    scanf("%d %d", &a, &b);
    psh(a, b), psh(b, a);
  }
  memset(dep, 0, sizeof(dep)), memset(te, 0, sizeof(te)), bn = 0;
  for (memset(bd, 0, sizeof(bd)), i = 1; i <= n; ++i)
    if (!bd[i]) dfs(i, 1);
  _cl();
  for (scanf("%d", &q), i = 0; i < q; ++i) {
    scanf("%d %d", &qr[i].l, &qr[i].r);
    qr[i].id = i;
  }
  __cl();
  for (i = 0; i < q; printf("%I64d\n", qr[i++].rs))
    ;
};
int main() {
  cl();
  return 0;
};
