#include <bits/stdc++.h>
using namespace std;
int n, m, q, used[300005], d[300005], up[300005], mn[300005], mx[300005],
    sf[300005];
vector<int> g[300005];
pair<int, int> t[4 * 300005];
long long pr[300005];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  return make_pair(max(a.first, b.first), min(a.second, b.second));
}
void upd(int v, int l, int r, int pos, pair<int, int> val) {
  if (l == r) {
    t[v] = val;
    return;
  }
  int m = (l + r) / 2;
  if (pos <= m)
    upd(v * 2, l, m, pos, val);
  else
    upd(v * 2 + 1, m + 1, r, pos, val);
  t[v] = merge(t[v * 2], t[v * 2 + 1]);
}
pair<int, int> get(int v, int l, int r, int i, int j) {
  if (i > j) return make_pair(0, 1000000007ll);
  if (l == i && r == j) return t[v];
  int m = (l + r) / 2;
  return merge(get(v * 2, l, m, i, min(j, m)),
               get(v * 2 + 1, m + 1, r, max(i, m + 1), j));
}
void dfs(int v, int p) {
  upd(1, 1, n, d[v], make_pair(v, v));
  used[v] = 1;
  mn[v] = 1000000007ll;
  vector<int> c;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to]) {
      if (d[to] < d[up[v]]) up[v] = to;
      continue;
    }
    d[to] = d[v] + 1;
    dfs(to, v);
    if (d[up[to]] < d[up[v]]) up[v] = up[to];
    c.push_back(to);
  }
  for (int i = 0; i < c.size(); i++) {
    int to = c[i];
    if (up[to] != up[v]) continue;
    mx[v] = max(mx[v], mx[to]);
    mn[v] = min(mn[v], mn[to]);
  }
  pair<int, int> mxn = get(1, 1, n, d[up[v]], d[v]);
  mx[v] = max(mx[v], mxn.first);
  mn[v] = min(mn[v], mxn.second);
  upd(1, 1, n, d[v], make_pair(0, 1000000007ll));
}
int main() {
  cin >> n >> m;
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  d[0] = 1000000007ll;
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      d[i] = 1;
      dfs(i, -1);
    }
  sf[n + 1] = 1000000007ll;
  for (int i = n; i >= 1; i--) {
    sf[i] = sf[i + 1];
    if (up[i] && mn[i] == i) sf[i] = min(sf[i], mx[i] - 1);
  }
  for (int i = 1; i <= n; i++) pr[i] = pr[i - 1] + sf[i] - i + 1;
  cin >> q;
  while (q--) {
    int L, R;
    scanf("%d%d", &L, &R);
    int l = L, r = R, m, pos = L - 1;
    while (l <= r) {
      m = (l + r) / 2;
      if (sf[m] <= R) {
        l = m + 1;
        pos = m;
      } else
        r = m - 1;
    }
    long long ans = pr[pos] - pr[L - 1];
    long long len = R - pos;
    ans += (len + 1ll) * (len) / 2;
    printf("%lld\n", ans);
  }
  return 0;
}

### Prompt

Your challenge is to write a cpp solution 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;
int n, m, q, used[300005], d[300005], up[300005], mn[300005], mx[300005],
    sf[300005];
vector<int> g[300005];
pair<int, int> t[4 * 300005];
long long pr[300005];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  return make_pair(max(a.first, b.first), min(a.second, b.second));
}
void upd(int v, int l, int r, int pos, pair<int, int> val) {
  if (l == r) {
    t[v] = val;
    return;
  }
  int m = (l + r) / 2;
  if (pos <= m)
    upd(v * 2, l, m, pos, val);
  else
    upd(v * 2 + 1, m + 1, r, pos, val);
  t[v] = merge(t[v * 2], t[v * 2 + 1]);
}
pair<int, int> get(int v, int l, int r, int i, int j) {
  if (i > j) return make_pair(0, 1000000007ll);
  if (l == i && r == j) return t[v];
  int m = (l + r) / 2;
  return merge(get(v * 2, l, m, i, min(j, m)),
               get(v * 2 + 1, m + 1, r, max(i, m + 1), j));
}
void dfs(int v, int p) {
  upd(1, 1, n, d[v], make_pair(v, v));
  used[v] = 1;
  mn[v] = 1000000007ll;
  vector<int> c;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to]) {
      if (d[to] < d[up[v]]) up[v] = to;
      continue;
    }
    d[to] = d[v] + 1;
    dfs(to, v);
    if (d[up[to]] < d[up[v]]) up[v] = up[to];
    c.push_back(to);
  }
  for (int i = 0; i < c.size(); i++) {
    int to = c[i];
    if (up[to] != up[v]) continue;
    mx[v] = max(mx[v], mx[to]);
    mn[v] = min(mn[v], mn[to]);
  }
  pair<int, int> mxn = get(1, 1, n, d[up[v]], d[v]);
  mx[v] = max(mx[v], mxn.first);
  mn[v] = min(mn[v], mxn.second);
  upd(1, 1, n, d[v], make_pair(0, 1000000007ll));
}
int main() {
  cin >> n >> m;
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  d[0] = 1000000007ll;
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      d[i] = 1;
      dfs(i, -1);
    }
  sf[n + 1] = 1000000007ll;
  for (int i = n; i >= 1; i--) {
    sf[i] = sf[i + 1];
    if (up[i] && mn[i] == i) sf[i] = min(sf[i], mx[i] - 1);
  }
  for (int i = 1; i <= n; i++) pr[i] = pr[i - 1] + sf[i] - i + 1;
  cin >> q;
  while (q--) {
    int L, R;
    scanf("%d%d", &L, &R);
    int l = L, r = R, m, pos = L - 1;
    while (l <= r) {
      m = (l + r) / 2;
      if (sf[m] <= R) {
        l = m + 1;
        pos = m;
      } else
        r = m - 1;
    }
    long long ans = pr[pos] - pr[L - 1];
    long long len = R - pos;
    ans += (len + 1ll) * (len) / 2;
    printf("%lld\n", ans);
  }
  return 0;
}

```