#include <bits/stdc++.h>
using namespace std;
const int mod = (1e9) + 7;
const int siz = 3e5 + 5, siz2 = 5e1 + 5;
int n, m, q;
vector<int> adj[siz];
bool vis[siz], inst[siz];
vector<int> st;
int startp[siz], endp[siz];
long long cumu[siz];
void dfs(int i, int p) {
  if (inst[i]) {
    int mn = INT_MAX, mx = INT_MIN;
    for (int j = st.size() - 1;; j--) {
      mn = min(mn, st[j]);
      mx = max(mx, st[j]);
      if (st[j] == i) break;
    }
    startp[mx] = max(startp[mx], mn);
    return;
  }
  if (vis[i]) return;
  vis[i] = true;
  inst[i] = true;
  st.push_back(i);
  int sz = adj[i].size();
  for (int j = 0; j < sz; j++) {
    if (adj[i][j] != p) dfs(adj[i][j], i);
  }
  inst[i] = false;
  st.pop_back();
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) startp[i] = INT_MIN;
  for (int i = 1; i <= n; i++) dfs(i, 0);
  int lp = 1, rp = 1;
  while (lp <= n) {
    while (startp[rp] < lp) rp++;
    endp[lp] = rp - 1;
    lp++;
  }
  for (int i = 1; i <= n; i++) cumu[i] = endp[i] - i + 1 + cumu[i - 1];
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int le = l, ri = r + 1;
    while (le != ri) {
      int mid = (le + ri) / 2;
      if (endp[mid] >= r)
        ri = mid;
      else
        le = mid + 1;
    }
    long long ans = cumu[le - 1] - cumu[l - 1];
    if (le != r + 1) {
      long long term = r - le + 1;
      ans += (term * (term + 1)) / 2;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}

### Prompt

Your task is to create 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;
const int mod = (1e9) + 7;
const int siz = 3e5 + 5, siz2 = 5e1 + 5;
int n, m, q;
vector<int> adj[siz];
bool vis[siz], inst[siz];
vector<int> st;
int startp[siz], endp[siz];
long long cumu[siz];
void dfs(int i, int p) {
  if (inst[i]) {
    int mn = INT_MAX, mx = INT_MIN;
    for (int j = st.size() - 1;; j--) {
      mn = min(mn, st[j]);
      mx = max(mx, st[j]);
      if (st[j] == i) break;
    }
    startp[mx] = max(startp[mx], mn);
    return;
  }
  if (vis[i]) return;
  vis[i] = true;
  inst[i] = true;
  st.push_back(i);
  int sz = adj[i].size();
  for (int j = 0; j < sz; j++) {
    if (adj[i][j] != p) dfs(adj[i][j], i);
  }
  inst[i] = false;
  st.pop_back();
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) startp[i] = INT_MIN;
  for (int i = 1; i <= n; i++) dfs(i, 0);
  int lp = 1, rp = 1;
  while (lp <= n) {
    while (startp[rp] < lp) rp++;
    endp[lp] = rp - 1;
    lp++;
  }
  for (int i = 1; i <= n; i++) cumu[i] = endp[i] - i + 1 + cumu[i - 1];
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int le = l, ri = r + 1;
    while (le != ri) {
      int mid = (le + ri) / 2;
      if (endp[mid] >= r)
        ri = mid;
      else
        le = mid + 1;
    }
    long long ans = cumu[le - 1] - cumu[l - 1];
    if (le != r + 1) {
      long long term = r - le + 1;
      ans += (term * (term + 1)) / 2;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}

```