#include <bits/stdc++.h>
using namespace std;
const int N = 510031;
int n, m;
vector<int> g[N];
int cut[N], R[N];
long long SR[N];
int tests;
vector<int> qu_list[N];
vector<int> updates[N];
pair<long long, long long> t[N * 4];
int test_l[N], test_r[N];
long long ans[N];
long long SumProg[N];
pair<long long, long long> combine(pair<long long, long long> p1,
                                   pair<long long, long long> p2) {
  p1.first += p2.first;
  p1.second += p2.second;
  return p1;
}
void add(int v, int tl, int tr, int ps, int val) {
  if (tl == tr) {
    t[v].first += 1;
    t[v].second += val;
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    add(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    add(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = combine(t[v * 2], t[v * 2 + 1]);
}
pair<long long, long long> get(int v, int tl, int tr, int l, int r) {
  if (l > r) return make_pair(0, 0);
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  return combine(
      get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
      get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r));
}
int used[N];
vector<int> cycle;
int par[N];
void restore_cycle(int v, int start) {
  cycle.clear();
  while (v != start) {
    cycle.push_back(v);
    v = par[v];
  }
  cycle.push_back(start);
  sort(cycle.begin(), cycle.end());
  R[cycle[0]] = cycle.back() - 1;
}
void dfs(int v, int p = -1) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p || used[to] == 2) continue;
    if (used[to]) {
      restore_cycle(v, to);
      continue;
    }
    par[to] = v;
    dfs(to, v);
  }
  used[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    SumProg[i] = SumProg[i - 1] + i - 1;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    R[i] = n;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    dfs(i);
  }
  for (int i = n - 1; i >= 1; i--) {
    R[i] = min(R[i], R[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    updates[R[i]].push_back(i);
    SR[i] = SR[i - 1] + R[i];
  }
  cin >> tests;
  for (int test = 1; test <= tests; test++) {
    cin >> test_l[test] >> test_r[test];
    qu_list[test_r[test]].push_back(test);
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < updates[i].size(); j++) {
      int ps = updates[i][j];
      add(1, 1, n, ps, i);
    }
    for (int j = 0; j < qu_list[i].size(); j++) {
      int test = qu_list[i][j];
      long long res = SR[test_r[test]] - SR[test_l[test] - 1];
      res -= SumProg[test_r[test]] - SumProg[test_l[test] - 1];
      pair<long long, long long> p = get(1, 1, n, test_l[test], test_r[test]);
      res -= p.second;
      res += p.first * test_r[test];
      ans[test] = res;
    }
  }
  for (int i = 1; i <= tests; i++) {
    cout << ans[i] << "\n";
  }
  cin.get();
  cin.get();
  return 0;
}

### Prompt

Create a solution in Cpp for 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;
const int N = 510031;
int n, m;
vector<int> g[N];
int cut[N], R[N];
long long SR[N];
int tests;
vector<int> qu_list[N];
vector<int> updates[N];
pair<long long, long long> t[N * 4];
int test_l[N], test_r[N];
long long ans[N];
long long SumProg[N];
pair<long long, long long> combine(pair<long long, long long> p1,
                                   pair<long long, long long> p2) {
  p1.first += p2.first;
  p1.second += p2.second;
  return p1;
}
void add(int v, int tl, int tr, int ps, int val) {
  if (tl == tr) {
    t[v].first += 1;
    t[v].second += val;
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    add(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    add(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = combine(t[v * 2], t[v * 2 + 1]);
}
pair<long long, long long> get(int v, int tl, int tr, int l, int r) {
  if (l > r) return make_pair(0, 0);
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  return combine(
      get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
      get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r));
}
int used[N];
vector<int> cycle;
int par[N];
void restore_cycle(int v, int start) {
  cycle.clear();
  while (v != start) {
    cycle.push_back(v);
    v = par[v];
  }
  cycle.push_back(start);
  sort(cycle.begin(), cycle.end());
  R[cycle[0]] = cycle.back() - 1;
}
void dfs(int v, int p = -1) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p || used[to] == 2) continue;
    if (used[to]) {
      restore_cycle(v, to);
      continue;
    }
    par[to] = v;
    dfs(to, v);
  }
  used[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    SumProg[i] = SumProg[i - 1] + i - 1;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    R[i] = n;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    dfs(i);
  }
  for (int i = n - 1; i >= 1; i--) {
    R[i] = min(R[i], R[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    updates[R[i]].push_back(i);
    SR[i] = SR[i - 1] + R[i];
  }
  cin >> tests;
  for (int test = 1; test <= tests; test++) {
    cin >> test_l[test] >> test_r[test];
    qu_list[test_r[test]].push_back(test);
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < updates[i].size(); j++) {
      int ps = updates[i][j];
      add(1, 1, n, ps, i);
    }
    for (int j = 0; j < qu_list[i].size(); j++) {
      int test = qu_list[i][j];
      long long res = SR[test_r[test]] - SR[test_l[test] - 1];
      res -= SumProg[test_r[test]] - SumProg[test_l[test] - 1];
      pair<long long, long long> p = get(1, 1, n, test_l[test], test_r[test]);
      res -= p.second;
      res += p.first * test_r[test];
      ans[test] = res;
    }
  }
  for (int i = 1; i <= tests; i++) {
    cout << ans[i] << "\n";
  }
  cin.get();
  cin.get();
  return 0;
}

```