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 inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int dfn[300010], low[300010], stack[300010], head[300010], end[600010],
    nxt[600010];
int bel[300010], f[300010][21], min[300010], max[300010], lm[300010],
    root[300010], size[300010];
bool ins[300010];
int top = 0, idx = 0, cnt = 0, cou = 0;
void link(int a, int b) {
  nxt[++cou] = head[a];
  head[a] = cou;
  end[cou] = b;
}
int query(int l, int r) {
  int lg = log2(r - l + 1);
  return std::max(f[l][lg], f[r - (1 << lg) + 1][lg]);
}
void tarjan(int cur, int last) {
  dfn[cur] = low[cur] = ++idx;
  ins[cur] = true;
  stack[++top] = cur;
  for (int x = head[cur]; x != -1; x = nxt[x]) {
    if (end[x] == last) continue;
    if (dfn[end[x]] == -1) {
      tarjan(end[x], cur);
      if (low[end[x]] < low[cur]) low[cur] = low[end[x]];
    } else if (ins[end[x]] && dfn[end[x]] < low[cur])
      low[cur] = dfn[end[x]];
  }
  if (dfn[cur] == low[cur]) {
    cnt++;
    do {
      bel[stack[top]] = cnt;
      ins[stack[top]] = false;
    } while (stack[top--] != cur);
  }
}
struct President_Tree {
  int lc[8000000], rc[8000000], cou[8000000];
  long long sum[8000000];
  int cnt;
  void init() {
    cnt = 0;
    memset(lc, 0, sizeof(lc));
    memset(rc, 0, sizeof(rc));
  }
  inline void push_up(int cur) {
    sum[cur] = sum[lc[cur]] + sum[rc[cur]];
    cou[cur] = cou[lc[cur]] + cou[rc[cur]];
  }
  void build(int &cur, int l, int r) {
    cur = ++cnt;
    sum[cur] = 0;
    cou[cur] = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(lc[cur], l, mid);
    build(rc[cur], mid + 1, r);
  }
  void insert(int &cur, int last, int l, int r, int x, int c) {
    cur = ++cnt;
    if (l == r) {
      sum[cur] = sum[last] + c;
      cou[cur] = cou[last] + 1;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) {
      rc[cur] = rc[last];
      insert(lc[cur], lc[last], l, mid, x, c);
    } else {
      lc[cur] = lc[last];
      insert(rc[cur], rc[last], mid + 1, r, x, c);
    }
    push_up(cur);
  }
  long long query(int cur, int last, int l, int r, int lim) {
    if (r <= lim)
      return (long long)(cou[cur] - cou[last]) * (long long)(lim);
    else if (l > lim)
      return (sum[cur] - sum[last]);
    int mid = (l + r) >> 1;
    return query(lc[cur], lc[last], l, mid, lim) +
           query(rc[cur], rc[last], mid + 1, r, lim);
  }
} t;
signed main() {
  memset(head, -1, sizeof(head));
  memset(dfn, -1, sizeof(dfn));
  int n = inp();
  int m = inp();
  for (int i = 1; i <= m; i++) {
    int u = inp();
    int v = inp();
    link(u, v);
    link(v, u);
  }
  for (int i = 1; i <= n; i++)
    if (dfn[i] == -1) tarjan(i, -1);
  memset(min, 0x3f, sizeof(min));
  for (int i = 1; i <= n; i++) {
    min[bel[i]] = std::min(min[bel[i]], i);
    max[bel[i]] = std::max(max[bel[i]], i);
    size[bel[i]]++;
  }
  for (int i = 1; i <= cnt; i++)
    if (size[i] >= 2) f[max[i]][0] = std::max(f[max[i]][0], min[i]);
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      f[i][j] = std::max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  t.init();
  t.build(root[0], 1, n);
  for (int i = 1; i <= n; i++) {
    int l = 1;
    int r = i;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (query(mid, i) >= mid)
        l = mid + 1;
      else
        r = mid;
    }
    t.insert(root[i], root[i - 1], 1, n, l, l);
  }
  int q = inp();
  while (q--) {
    int l = inp();
    int r = inp();
    std::cout << ((long long)(r) * (long long)(r + 1) >> 1) -
                     ((long long)(l - 1) * (long long)(l - 1 + 1) >> 1) -
                     t.query(root[r], root[l - 1], 1, n, l) + (r - l + 1)
              << std::endl;
  }
}
