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>
#include <bits/stdc++.h>
int n, m, head[300005], cnt, vis[300005], stk[300005], top, del[300005],
    near[300005], Q;
long long sum[300005];
struct edge {
  int v, next;
} e[300005 << 1];
void add(int u, int v) {
  e[++cnt] = (edge){v, head[u]};
  head[u] = cnt;
}
class Segment_Tree {
  struct tree {
    int l, r, v, tag;
  } t[300005 << 2];
  void pushup(int x) { t[x].v = std::min(t[x << 1].v, t[x << 1 | 1].v); }
  void pushdown(int x) {
    if (t[x].tag == 1e9) return;
    t[x << 1].tag = std::min(t[x << 1].tag, t[x].tag);
    t[x << 1 | 1].tag = std::min(t[x << 1 | 1].tag, t[x].tag);
    t[x << 1].v = std::min(t[x << 1].v, t[x << 1].tag);
    t[x << 1 | 1].v = std::min(t[x << 1 | 1].v, t[x << 1 | 1].tag);
    t[x].tag = 1e9;
  }

 public:
  void bulid(int x, int l, int r) {
    t[x].l = l, t[x].r = r;
    t[x].tag = 1e9;
    if (l == r) return (void)(t[x].v = n);
    int mid = (l + r) >> 1;
    bulid(x << 1, l, mid), bulid(x << 1 | 1, mid + 1, r);
    pushup(x);
  }
  void update(int x, int l, int r, int v) {
    if (l <= t[x].l && t[x].r <= r) {
      t[x].v = std::min(t[x].v, v);
      t[x].tag = std::min(t[x].tag, v);
      return;
    }
    pushdown(x);
    int mid = (t[x].l + t[x].r) >> 1;
    if (l <= mid) update(x << 1, l, r, v);
    if (r > mid) update(x << 1 | 1, l, r, v);
    pushup(x);
  }
  int query(int x, int l, int r) {
    if (l <= t[x].l && t[x].r <= r) return t[x].v;
    pushdown(x);
    int mid = (t[x].l + t[x].r) >> 1, res = 1e9;
    if (l <= mid) res = std::min(res, query(x << 1, l, r));
    if (r > mid) res = std::min(res, query(x << 1 | 1, l, r));
    return res;
  }
} T;
void dfs(int u, int fa) {
  vis[u] = 1, stk[++top] = u;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].v;
    if (v == fa || del[v]) continue;
    if (vis[v]) {
      int l = 1e9, r = 0;
      while (top) {
        del[stk[top]] = 1;
        l = std::min(stk[top], l);
        r = std::max(stk[top], r);
        if (stk[top--] == v) break;
      }
      T.update(1, 1, l, r - 1);
    } else
      dfs(v, u);
  }
  if (del[u] == 0) top--;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++)
    scanf("%d%d", &u, &v), add(u, v), add(v, u);
  T.bulid(1, 1, n);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  for (int i = 1; i <= n; i++)
    near[i] = T.query(1, i, i), sum[i] = sum[i - 1] + near[i];
  scanf("%d", &Q);
  while (Q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int prt = std::lower_bound(near + l, near + 1 + r, r) - near - 1;
    long long cnt1 = prt - l + 1, cnt2 = r - prt;
    long long ans = sum[prt] - sum[l - 1] - (2 * l - 3 + cnt1) * cnt1 / 2 +
                    (1 + cnt2) * cnt2 / 2;
    printf("%I64d\n", ans);
  }
  return 0;
}
