#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 3e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
vector<int> ger[maxn];
bool vis[maxn];
int rang[maxn];
int dfs(int a, int par) {
  if (rang[a] != -1) {
    return -1;
  }
  if (vis[a]) {
    return a;
  }
  vis[a] = 1;
  int dor = -1;
  for (int i = 0; i < ger[a].size(); i++) {
    int v = ger[a][i];
    if (v != par) {
      int u = dfs(v, a);
      if (u != -1) {
        dor = u;
      }
    }
  }
  rang[a] = dor;
  if (dor == a) {
    return -1;
  }
  return dor;
}
void ffty(int n) {
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs(i, -1);
    }
  }
}
long long ans[maxn];
int f[maxn];
vector<int> vec[maxn];
int r[maxn];
int fir[maxn];
int las[maxn];
int s[maxn * 8];
long long sum[maxn * 8];
int hes(int s, int d, int t) { return s * t + (t - 1) * t * d / 2; }
void update(int L, int R, int node, int l, int r) {
  if (l <= L && R <= r) {
    s[node]++;
    sum[node] =
        (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
    return;
  }
  if (R <= l || r <= L) {
    return;
  }
  int mid = (L + R) / 2;
  update(L, mid, 2 * node, l, r);
  update(mid, R, 2 * node + 1, l, r);
  sum[node] = (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
}
long long finds(int l, int r, int node, int x) {
  if (l + 1 == r) {
    return s[node];
  }
  int mid = (l + r) / 2;
  if (x < mid) {
    return (long long)s[node] * (x - l + 1) + finds(l, mid, 2 * node, x);
  }
  return (long long)s[node] * (x - l + 1) + sum[2 * node] +
         finds(mid, r, 2 * node + 1, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(rang, rang + maxn, -1);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(v);
    ger[v].push_back(u);
  }
  ffty(n);
  fill(fir, fir + maxn, inf);
  for (int i = 0; i < n; i++) {
    if (rang[i] != -1) {
      fir[rang[i]] = min(fir[rang[i]], i);
      las[rang[i]] = max(las[rang[i]], i);
    }
  }
  f[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    int c = rang[i];
    if (c == -1) {
      f[i] = f[i + 1];
      continue;
    }
    f[i] = f[i + 1];
    if (fir[rang[i]] == i) {
      f[i] = min(f[i], las[rang[i]]);
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l;
    cin >> l >> r[i];
    l--;
    r[i]--;
    vec[l].push_back(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    update(0, n, 1, i, f[i]);
    for (int j = 0; j < vec[i].size(); j++) {
      ans[vec[i][j]] = finds(0, n, 1, r[vec[i][j]]);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
const int maxn = 3e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
vector<int> ger[maxn];
bool vis[maxn];
int rang[maxn];
int dfs(int a, int par) {
  if (rang[a] != -1) {
    return -1;
  }
  if (vis[a]) {
    return a;
  }
  vis[a] = 1;
  int dor = -1;
  for (int i = 0; i < ger[a].size(); i++) {
    int v = ger[a][i];
    if (v != par) {
      int u = dfs(v, a);
      if (u != -1) {
        dor = u;
      }
    }
  }
  rang[a] = dor;
  if (dor == a) {
    return -1;
  }
  return dor;
}
void ffty(int n) {
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs(i, -1);
    }
  }
}
long long ans[maxn];
int f[maxn];
vector<int> vec[maxn];
int r[maxn];
int fir[maxn];
int las[maxn];
int s[maxn * 8];
long long sum[maxn * 8];
int hes(int s, int d, int t) { return s * t + (t - 1) * t * d / 2; }
void update(int L, int R, int node, int l, int r) {
  if (l <= L && R <= r) {
    s[node]++;
    sum[node] =
        (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
    return;
  }
  if (R <= l || r <= L) {
    return;
  }
  int mid = (L + R) / 2;
  update(L, mid, 2 * node, l, r);
  update(mid, R, 2 * node + 1, l, r);
  sum[node] = (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
}
long long finds(int l, int r, int node, int x) {
  if (l + 1 == r) {
    return s[node];
  }
  int mid = (l + r) / 2;
  if (x < mid) {
    return (long long)s[node] * (x - l + 1) + finds(l, mid, 2 * node, x);
  }
  return (long long)s[node] * (x - l + 1) + sum[2 * node] +
         finds(mid, r, 2 * node + 1, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(rang, rang + maxn, -1);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(v);
    ger[v].push_back(u);
  }
  ffty(n);
  fill(fir, fir + maxn, inf);
  for (int i = 0; i < n; i++) {
    if (rang[i] != -1) {
      fir[rang[i]] = min(fir[rang[i]], i);
      las[rang[i]] = max(las[rang[i]], i);
    }
  }
  f[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    int c = rang[i];
    if (c == -1) {
      f[i] = f[i + 1];
      continue;
    }
    f[i] = f[i + 1];
    if (fir[rang[i]] == i) {
      f[i] = min(f[i], las[rang[i]]);
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l;
    cin >> l >> r[i];
    l--;
    r[i]--;
    vec[l].push_back(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    update(0, n, 1, i, f[i]);
    for (int j = 0; j < vec[i].size(); j++) {
      ans[vec[i][j]] = finds(0, n, 1, r[vec[i][j]]);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}

```