#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
vector<int> G[300005];
int maxi[300005], used[300005], stk[300005], vf;
long long prefix[300005];
void read() {
  cin >> N >> M;
  int a, b;
  for (int i = 1; i <= M; ++i) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= N; ++i) maxi[i] = N;
}
long long query(int from, int to) {
  long long l = from, r = to, m;
  while (l <= r) {
    m = (l + r) >> 1LL;
    if (maxi[m] <= to)
      l = m + 1;
    else
      r = m - 1;
  }
  return prefix[r] - prefix[from - 1] + ((to - r) * (to - r + 1) >> 1LL);
}
void DFS(int k, int from) {
  used[k] = 1;
  stk[vf++] = k;
  for (auto it : G[k])
    if (used[it] == 0)
      DFS(it, k);
    else if (used[it] == 1 && it != from) {
      int mx = it;
      int mn = it;
      int crt = vf - 1;
      while (stk[crt] != it) {
        mx = max(mx, stk[crt]);
        mn = min(mn, stk[crt]);
        --crt;
      }
      used[it] = 2;
      maxi[mn] = mx - 1;
    }
  used[k] = 2;
  --vf;
}
void getSegments() {
  for (int i = 1; i <= N; ++i)
    if (!used[i]) DFS(i, 0);
  for (int i = N - 1; i >= 1; --i) maxi[i] = min(maxi[i], maxi[i + 1]);
  prefix[1] = maxi[1];
  for (int i = 2; i <= N; ++i)
    prefix[i] = prefix[i - 1] + maxi[i] * 1LL - i + 1;
}
void answer() {
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << query(l, r) << "\n";
  }
}
int main() {
  cin.sync_with_stdio(false);
  read();
  getSegments();
  answer();
  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;
int N, M, Q;
vector<int> G[300005];
int maxi[300005], used[300005], stk[300005], vf;
long long prefix[300005];
void read() {
  cin >> N >> M;
  int a, b;
  for (int i = 1; i <= M; ++i) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= N; ++i) maxi[i] = N;
}
long long query(int from, int to) {
  long long l = from, r = to, m;
  while (l <= r) {
    m = (l + r) >> 1LL;
    if (maxi[m] <= to)
      l = m + 1;
    else
      r = m - 1;
  }
  return prefix[r] - prefix[from - 1] + ((to - r) * (to - r + 1) >> 1LL);
}
void DFS(int k, int from) {
  used[k] = 1;
  stk[vf++] = k;
  for (auto it : G[k])
    if (used[it] == 0)
      DFS(it, k);
    else if (used[it] == 1 && it != from) {
      int mx = it;
      int mn = it;
      int crt = vf - 1;
      while (stk[crt] != it) {
        mx = max(mx, stk[crt]);
        mn = min(mn, stk[crt]);
        --crt;
      }
      used[it] = 2;
      maxi[mn] = mx - 1;
    }
  used[k] = 2;
  --vf;
}
void getSegments() {
  for (int i = 1; i <= N; ++i)
    if (!used[i]) DFS(i, 0);
  for (int i = N - 1; i >= 1; --i) maxi[i] = min(maxi[i], maxi[i + 1]);
  prefix[1] = maxi[1];
  for (int i = 2; i <= N; ++i)
    prefix[i] = prefix[i - 1] + maxi[i] * 1LL - i + 1;
}
void answer() {
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << query(l, r) << "\n";
  }
}
int main() {
  cin.sync_with_stdio(false);
  read();
  getSegments();
  answer();
  return 0;
}

```