#include <bits/stdc++.h>
using namespace std;
typedef struct _Edge {
  int to;
  int next;
} Edge;
Edge arr[600010];
int head[300010], arrPt;
stack<int> stk;
bool hasVisited[300010], inStack[300010];
int pfxMaxMinPt[300010];
long long int pfxMaxMinPtSum[300010];
int vertexNum, edgeNum;
void addEdge(int from, int to) {
  arr[arrPt] = {to, head[from]};
  head[from] = arrPt++;
}
void dfs(int cntPt, int prevPt) {
  hasVisited[cntPt] = true;
  inStack[cntPt] = true;
  stk.push(cntPt);
  for (int i = head[cntPt]; i != -1; i = arr[i].next) {
    int nextPt = arr[i].to;
    if (nextPt == prevPt) continue;
    if (hasVisited[nextPt] && !inStack[nextPt]) continue;
    if (hasVisited[nextPt]) {
      int minPt = INT_MAX, maxPt = -1;
      while (!stk.empty()) {
        int cntTop = stk.top();
        stk.pop();
        inStack[cntTop] = false;
        minPt = min(minPt, cntTop);
        maxPt = max(maxPt, cntTop);
        if (cntTop == nextPt) break;
      }
      pfxMaxMinPt[maxPt] = max(pfxMaxMinPt[maxPt], minPt);
    } else {
      dfs(nextPt, cntPt);
    }
  }
  if (!stk.empty() && stk.top() == cntPt) {
    stk.pop();
    inStack[cntPt] = false;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(head, -1, sizeof(head));
  arrPt = 0;
  cin >> vertexNum >> edgeNum;
  for (int i = 0; i < edgeNum; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;
    addEdge(from, to);
    addEdge(to, from);
  }
  memset(inStack, false, sizeof(inStack));
  memset(hasVisited, false, sizeof(hasVisited));
  memset(pfxMaxMinPt, -1, sizeof(pfxMaxMinPt));
  for (int i = 0; i < vertexNum; i++) {
    assert(stk.empty() == true);
    if (!hasVisited[i]) dfs(i, -1);
  }
  pfxMaxMinPtSum[0] = pfxMaxMinPt[0];
  for (int i = 1; i < vertexNum; i++) {
    pfxMaxMinPt[i] = max(pfxMaxMinPt[i], pfxMaxMinPt[i - 1]);
    pfxMaxMinPtSum[i] = pfxMaxMinPtSum[i - 1] + pfxMaxMinPt[i];
  }
  int qNum;
  cin >> qNum;
  while (qNum--) {
    int qLeftPt, qRightPt;
    cin >> qLeftPt >> qRightPt;
    qLeftPt--;
    qRightPt--;
    long long int ans =
        ((long long int)(qLeftPt + qRightPt) * (qRightPt - qLeftPt + 1)) >> 1;
    int pos = upper_bound(pfxMaxMinPt + qLeftPt, pfxMaxMinPt + qRightPt + 1,
                          qLeftPt - 1) -
              (pfxMaxMinPt + qLeftPt) - 1;
    ans -= (long long int)(qLeftPt - 1) * (pos + 1) +
           (qLeftPt + pos <= qRightPt
                ? pfxMaxMinPtSum[qRightPt] -
                      (qLeftPt + pos >= 0 ? pfxMaxMinPtSum[qLeftPt + pos] : 0)
                : 0);
    cout << ans << endl;
  }
  return 0;
}

### Prompt

Please formulate 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;
typedef struct _Edge {
  int to;
  int next;
} Edge;
Edge arr[600010];
int head[300010], arrPt;
stack<int> stk;
bool hasVisited[300010], inStack[300010];
int pfxMaxMinPt[300010];
long long int pfxMaxMinPtSum[300010];
int vertexNum, edgeNum;
void addEdge(int from, int to) {
  arr[arrPt] = {to, head[from]};
  head[from] = arrPt++;
}
void dfs(int cntPt, int prevPt) {
  hasVisited[cntPt] = true;
  inStack[cntPt] = true;
  stk.push(cntPt);
  for (int i = head[cntPt]; i != -1; i = arr[i].next) {
    int nextPt = arr[i].to;
    if (nextPt == prevPt) continue;
    if (hasVisited[nextPt] && !inStack[nextPt]) continue;
    if (hasVisited[nextPt]) {
      int minPt = INT_MAX, maxPt = -1;
      while (!stk.empty()) {
        int cntTop = stk.top();
        stk.pop();
        inStack[cntTop] = false;
        minPt = min(minPt, cntTop);
        maxPt = max(maxPt, cntTop);
        if (cntTop == nextPt) break;
      }
      pfxMaxMinPt[maxPt] = max(pfxMaxMinPt[maxPt], minPt);
    } else {
      dfs(nextPt, cntPt);
    }
  }
  if (!stk.empty() && stk.top() == cntPt) {
    stk.pop();
    inStack[cntPt] = false;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(head, -1, sizeof(head));
  arrPt = 0;
  cin >> vertexNum >> edgeNum;
  for (int i = 0; i < edgeNum; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;
    addEdge(from, to);
    addEdge(to, from);
  }
  memset(inStack, false, sizeof(inStack));
  memset(hasVisited, false, sizeof(hasVisited));
  memset(pfxMaxMinPt, -1, sizeof(pfxMaxMinPt));
  for (int i = 0; i < vertexNum; i++) {
    assert(stk.empty() == true);
    if (!hasVisited[i]) dfs(i, -1);
  }
  pfxMaxMinPtSum[0] = pfxMaxMinPt[0];
  for (int i = 1; i < vertexNum; i++) {
    pfxMaxMinPt[i] = max(pfxMaxMinPt[i], pfxMaxMinPt[i - 1]);
    pfxMaxMinPtSum[i] = pfxMaxMinPtSum[i - 1] + pfxMaxMinPt[i];
  }
  int qNum;
  cin >> qNum;
  while (qNum--) {
    int qLeftPt, qRightPt;
    cin >> qLeftPt >> qRightPt;
    qLeftPt--;
    qRightPt--;
    long long int ans =
        ((long long int)(qLeftPt + qRightPt) * (qRightPt - qLeftPt + 1)) >> 1;
    int pos = upper_bound(pfxMaxMinPt + qLeftPt, pfxMaxMinPt + qRightPt + 1,
                          qLeftPt - 1) -
              (pfxMaxMinPt + qLeftPt) - 1;
    ans -= (long long int)(qLeftPt - 1) * (pos + 1) +
           (qLeftPt + pos <= qRightPt
                ? pfxMaxMinPtSum[qRightPt] -
                      (qLeftPt + pos >= 0 ? pfxMaxMinPtSum[qLeftPt + pos] : 0)
                : 0);
    cout << ans << endl;
  }
  return 0;
}

```