#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, q, mx[300005];
long long acu[300005];
vector<vector<int> > adj;
int maxi, mini, p[300005];
void ciclo(int u, int v) {
  if (v == u) return;
  maxi = max(u, maxi);
  mini = min(u, mini);
  ciclo(p[u], v);
}
vector<int> vis;
void dfs(int u) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (vis[v]) {
      if (vis[v] == 1 && v != p[u]) {
        maxi = mini = v;
        ciclo(u, v);
        mx[mini] = min(mx[mini], maxi - 1);
      }
    } else {
      p[v] = u;
      dfs(v);
    }
  }
  vis[u] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  adj = vector<vector<int> >(n + 1);
  while (m--) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vis = vector<int>(n + 1);
  fill(mx, mx + n + 1, n);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      p[i] = i;
      dfs(i);
    }
  }
  for (int i = n - 1; i; i--) mx[i] = min(mx[i], mx[i + 1]);
  acu[0] = 0;
  for (int i = 1; i <= n; i++) acu[i] = acu[i - 1] + mx[i] - i + 1;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    long long x = lower_bound(mx + 1, mx + n + 1, b) - mx;
    if (x < a) {
      x = b - a + 1;
      cout << x * (x + 1) / 2 << '\n';
    } else {
      long long d = b - x + 1;
      cout << d * (d + 1) / 2 + acu[x - 1] - acu[a - 1] << '\n';
    }
  }
  return 0;
}

### Prompt

In cpp, your task is to solve 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, a, b, q, mx[300005];
long long acu[300005];
vector<vector<int> > adj;
int maxi, mini, p[300005];
void ciclo(int u, int v) {
  if (v == u) return;
  maxi = max(u, maxi);
  mini = min(u, mini);
  ciclo(p[u], v);
}
vector<int> vis;
void dfs(int u) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (vis[v]) {
      if (vis[v] == 1 && v != p[u]) {
        maxi = mini = v;
        ciclo(u, v);
        mx[mini] = min(mx[mini], maxi - 1);
      }
    } else {
      p[v] = u;
      dfs(v);
    }
  }
  vis[u] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  adj = vector<vector<int> >(n + 1);
  while (m--) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vis = vector<int>(n + 1);
  fill(mx, mx + n + 1, n);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      p[i] = i;
      dfs(i);
    }
  }
  for (int i = n - 1; i; i--) mx[i] = min(mx[i], mx[i + 1]);
  acu[0] = 0;
  for (int i = 1; i <= n; i++) acu[i] = acu[i - 1] + mx[i] - i + 1;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    long long x = lower_bound(mx + 1, mx + n + 1, b) - mx;
    if (x < a) {
      x = b - a + 1;
      cout << x * (x + 1) / 2 << '\n';
    } else {
      long long d = b - x + 1;
      cout << d * (d + 1) / 2 + acu[x - 1] - acu[a - 1] << '\n';
    }
  }
  return 0;
}

```