#include <bits/stdc++.h>
using namespace std;
ofstream out("output.txt");
struct cyclevertexes {
  int min_num;
  int max_num;
  cyclevertexes() : min_num(0), max_num(0) {}
  cyclevertexes(int a, int b) : min_num(a), max_num(b) {}
  bool operator<(const cyclevertexes &c) const {
    if (min_num == c.min_num) return max_num < c.max_num;
    return min_num < c.min_num;
  }
};
vector<vector<int>> graph;
vector<int> color;
vector<bool> was;
vector<cyclevertexes> cycle;
stack<int> rec;
cyclevertexes get_cycle(int v) {
  int min_num = 1e9 - 10, max_num = -10, use_v = 0;
  while (!rec.empty() && color[rec.top()] == 1) {
    int t = rec.top();
    if (t == v) {
      ++use_v;
      if (use_v == 2) break;
    }
    rec.pop();
    min_num = min(min_num, t);
    max_num = max(max_num, t);
  }
  return cyclevertexes(min_num, max_num);
}
void dfs(int v, int p = -1) {
  rec.push(v);
  if (color[v] >= 2) {
    return;
  }
  if (color[v] == 1) {
    cycle.push_back(get_cycle(v));
    return;
  }
  color[v] = 1;
  for (int u : graph[v]) {
    if (u != p) dfs(u, v);
  }
  color[v] = 2;
  if (!rec.empty() && rec.top() == v) rec.pop();
}
long long binsearch(vector<long long> &L, long long l) {
  long long left = 0, right = (long long)L.size();
  while (right - left > 1) {
    long long middle = (left + right) / 2;
    if (L[middle] > l)
      right = middle;
    else
      left = middle;
  }
  return left;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  graph.resize(n);
  for (int i = 0; i < m; ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    graph[--from].push_back(--to);
    graph[to].push_back(from);
  }
  color.resize(n, 0);
  was.resize(n, false);
  for (int i = 0; i < n; ++i) dfs(i);
  vector<long long> fromposnum(n, 1e7);
  for (int i = 0; i < (int)cycle.size(); ++i) fromposnum[cycle[i].max_num] = i;
  vector<long long> L(n);
  int pos = 0, r = 0;
  while (r < n) {
    if (fromposnum[r] == 1e7) {
      L[r] = pos;
      ++r;
      continue;
    }
    pos = max(pos, cycle[fromposnum[r]].min_num + 1);
    L[r] = pos;
    ++r;
  }
  vector<long long> Lsums(n);
  Lsums[0] = L[0];
  for (int i = 1; i < n; ++i) Lsums[i] = Lsums[i - 1] + L[i];
  int query;
  scanf("%d", &query);
  for (int i = 0; i < query; ++i) {
    long long left, right;
    scanf("%lld%lld", &left, &right);
    --left;
    --right;
    long long M = max(left, min(binsearch(L, left), right));
    long long ans = (1LL - left) * (M - left + 1LL) +
                    (long long)(left + M) * (M - left + 1LL) / 2;
    ans += (M + 1LL + right) * (right - M) / 2 - (Lsums[right] - Lsums[M]) +
           (right - M);
    printf("%lld\n", ans);
  }
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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;
ofstream out("output.txt");
struct cyclevertexes {
  int min_num;
  int max_num;
  cyclevertexes() : min_num(0), max_num(0) {}
  cyclevertexes(int a, int b) : min_num(a), max_num(b) {}
  bool operator<(const cyclevertexes &c) const {
    if (min_num == c.min_num) return max_num < c.max_num;
    return min_num < c.min_num;
  }
};
vector<vector<int>> graph;
vector<int> color;
vector<bool> was;
vector<cyclevertexes> cycle;
stack<int> rec;
cyclevertexes get_cycle(int v) {
  int min_num = 1e9 - 10, max_num = -10, use_v = 0;
  while (!rec.empty() && color[rec.top()] == 1) {
    int t = rec.top();
    if (t == v) {
      ++use_v;
      if (use_v == 2) break;
    }
    rec.pop();
    min_num = min(min_num, t);
    max_num = max(max_num, t);
  }
  return cyclevertexes(min_num, max_num);
}
void dfs(int v, int p = -1) {
  rec.push(v);
  if (color[v] >= 2) {
    return;
  }
  if (color[v] == 1) {
    cycle.push_back(get_cycle(v));
    return;
  }
  color[v] = 1;
  for (int u : graph[v]) {
    if (u != p) dfs(u, v);
  }
  color[v] = 2;
  if (!rec.empty() && rec.top() == v) rec.pop();
}
long long binsearch(vector<long long> &L, long long l) {
  long long left = 0, right = (long long)L.size();
  while (right - left > 1) {
    long long middle = (left + right) / 2;
    if (L[middle] > l)
      right = middle;
    else
      left = middle;
  }
  return left;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  graph.resize(n);
  for (int i = 0; i < m; ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    graph[--from].push_back(--to);
    graph[to].push_back(from);
  }
  color.resize(n, 0);
  was.resize(n, false);
  for (int i = 0; i < n; ++i) dfs(i);
  vector<long long> fromposnum(n, 1e7);
  for (int i = 0; i < (int)cycle.size(); ++i) fromposnum[cycle[i].max_num] = i;
  vector<long long> L(n);
  int pos = 0, r = 0;
  while (r < n) {
    if (fromposnum[r] == 1e7) {
      L[r] = pos;
      ++r;
      continue;
    }
    pos = max(pos, cycle[fromposnum[r]].min_num + 1);
    L[r] = pos;
    ++r;
  }
  vector<long long> Lsums(n);
  Lsums[0] = L[0];
  for (int i = 1; i < n; ++i) Lsums[i] = Lsums[i - 1] + L[i];
  int query;
  scanf("%d", &query);
  for (int i = 0; i < query; ++i) {
    long long left, right;
    scanf("%lld%lld", &left, &right);
    --left;
    --right;
    long long M = max(left, min(binsearch(L, left), right));
    long long ans = (1LL - left) * (M - left + 1LL) +
                    (long long)(left + M) * (M - left + 1LL) / 2;
    ans += (M + 1LL + right) * (right - M) / 2 - (Lsums[right] - Lsums[M]) +
           (right - M);
    printf("%lld\n", ans);
  }
  return 0;
}

```