#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long z = qp(x, y / 2);
  z = z * z % 1000000007;
  if (y & 1) z = z * x % 1000000007;
  return z;
}
long long n, m, q, i, j, cnt, vis[600005], vis2[600005], col[600005], top,
    mx[600005], mi[600005], ans[600005], ans2[600005];
vector<long long> wyx[600005];
long long st[600005];
bool dfs(long long x, long long fa) {
  vis[x] = 1;
  long long i;
  for (i = 0; i < wyx[x].size(); i++) {
    if (wyx[x][i] == fa) continue;
    st[++top] = x;
    vis2[x] = 1;
    if (!vis[wyx[x][i]]) {
      if (dfs(wyx[x][i], x))
        ;
    } else if (vis[wyx[x][i]] == 1) {
      long long mi = x, mx = x;
      cnt++;
      while (top && st[top] != wyx[x][i]) {
        mi = min(mi, st[top]);
        mx = max(mx, st[top--]);
      }
      mi = min(mi, st[top]);
      mx = max(mx, st[top--]);
      ans[mi] = mx;
    }
  }
  if (top && st[top] == x) top--;
  vis[x] = 2;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    wyx[x].push_back(y);
    wyx[y].push_back(x);
  }
  for (i = 1; i <= n + 1; i++) ans[i] = n + 1;
  for (i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  for (i = n; i; i--) {
    ans[i] = min(ans[i], ans[i + 1]);
    ans2[i] = ans2[i + 1] + ans[i] - i;
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    long long x, y;
    cin >> x >> y;
    long long t = upper_bound(ans + x, ans + y + 1, y) - ans;
    cout << ans2[x] - ans2[t] + (y - t + 2) * (y - t + 1) / 2 << endl;
  }
  return 0;
}

### Prompt

Your challenge is to write 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;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long z = qp(x, y / 2);
  z = z * z % 1000000007;
  if (y & 1) z = z * x % 1000000007;
  return z;
}
long long n, m, q, i, j, cnt, vis[600005], vis2[600005], col[600005], top,
    mx[600005], mi[600005], ans[600005], ans2[600005];
vector<long long> wyx[600005];
long long st[600005];
bool dfs(long long x, long long fa) {
  vis[x] = 1;
  long long i;
  for (i = 0; i < wyx[x].size(); i++) {
    if (wyx[x][i] == fa) continue;
    st[++top] = x;
    vis2[x] = 1;
    if (!vis[wyx[x][i]]) {
      if (dfs(wyx[x][i], x))
        ;
    } else if (vis[wyx[x][i]] == 1) {
      long long mi = x, mx = x;
      cnt++;
      while (top && st[top] != wyx[x][i]) {
        mi = min(mi, st[top]);
        mx = max(mx, st[top--]);
      }
      mi = min(mi, st[top]);
      mx = max(mx, st[top--]);
      ans[mi] = mx;
    }
  }
  if (top && st[top] == x) top--;
  vis[x] = 2;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    wyx[x].push_back(y);
    wyx[y].push_back(x);
  }
  for (i = 1; i <= n + 1; i++) ans[i] = n + 1;
  for (i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  for (i = n; i; i--) {
    ans[i] = min(ans[i], ans[i + 1]);
    ans2[i] = ans2[i + 1] + ans[i] - i;
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    long long x, y;
    cin >> x >> y;
    long long t = upper_bound(ans + x, ans + y + 1, y) - ans;
    cout << ans2[x] - ans2[t] + (y - t + 2) * (y - t + 1) / 2 << endl;
  }
  return 0;
}

```