#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;
};

### Prompt

Please create a solution in Cpp to the following problem:

You are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. Let's enumerate vertices from 1 to n. 

You have to answer q queries. Each query is described by a segment of vertices [l; r], and you have to count the number of its subsegments [x; y] (l ≤ x ≤ y ≤ r), such that if we delete all vertices except the segment of vertices [x; y] (including x and y) and edges between them, the resulting graph is bipartite.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — the number of vertices and the number of edges in the graph.

The next m lines describe edges in the graph. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting an edge between vertices ai and bi. It is guaranteed that this graph does not contain edge-simple cycles of even length.

The next line contains a single integer q (1 ≤ q ≤ 3·105) — the number of queries.

The next q lines contain queries. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the query parameters.

Output

Print q numbers, each in new line: the i-th of them should be the number of subsegments [x; y] (li ≤ x ≤ y ≤ ri), such that the graph that only includes vertices from segment [x; y] and edges between them is bipartite.

Examples

Input

6 6
1 2
2 3
3 1
4 5
5 6
6 4
3
1 3
4 6
1 6


Output

5
5
14


Input

8 9
1 2
2 3
3 1
4 5
5 6
6 7
7 8
8 4
7 2
3
1 8
1 4
3 8


Output

27
8
19

Note

The first example is shown on the picture below:

<image>

For the first query, all subsegments of [1; 3], except this segment itself, are suitable.

For the first query, all subsegments of [4; 6], except this segment itself, are suitable.

For the third query, all subsegments of [1; 6] are suitable, except [1; 3], [1; 4], [1; 5], [1; 6], [2; 6], [3; 6], [4; 6].

The second example is shown on the picture below:

<image>

### Response

```cpp
#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;
};

```