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>
using namespace std;
inline int read() {
  int sum = 0, fg = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fg = -1;
  for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
  return fg * sum;
}
const int maxn = 3e5 + 10;
vector<int> g[maxn];
vector<pair<int, int> > v[maxn];
int d[maxn], low[maxn], pre[maxn], dfn;
int S[maxn], top, cnt, n, m, q;
pair<int, int> p[maxn];
long long ans[maxn];
void tarjan(int now, int f) {
  d[now] = low[now] = ++dfn;
  S[++top] = now;
  for (int i = 0; i < g[now].size(); i++) {
    int son = g[now][i];
    if (son == f) continue;
    if (!d[son]) {
      tarjan(son, now);
      low[now] = min(low[now], low[son]);
      if (low[son] >= d[now]) {
        int Max = 0, Min = n + 1, tot = 0;
        while (top) {
          int x = S[top--];
          Max = max(Max, x);
          Min = min(Min, x);
          ++tot;
          if (x == son) break;
        }
        Max = max(Max, now), Min = min(Min, now);
        if (tot > 1) p[++cnt] = (pair<int, int>){Max, Min};
      }
    } else
      low[now] = min(low[now], d[son]);
  }
}
namespace ST {
long long A[maxn << 2], tag[maxn << 2];
void push_up(int rt) { A[rt] = A[(rt << 1)] + A[(rt << 1 | 1)]; }
void push_down(int rt, int l, int r) {
  if (!tag[rt]) return;
  int mid = (l + r) >> 1;
  tag[(rt << 1)] += tag[rt];
  tag[(rt << 1 | 1)] += tag[rt];
  A[(rt << 1)] += tag[rt] * (mid - l + 1);
  A[(rt << 1 | 1)] += tag[rt] * (r - mid);
  tag[rt] = 0;
}
void change(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    A[rt] += r - l + 1, ++tag[rt];
    return;
  }
  push_down(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) change((rt << 1), l, mid, L, R);
  if (R > mid) change((rt << 1 | 1), mid + 1, r, L, R);
  push_up(rt);
}
long long query(int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return A[rt];
  push_down(rt, l, r);
  int mid = (l + r) >> 1;
  long long res = 0;
  if (L <= mid) res += query((rt << 1), l, mid, L, R);
  if (R > mid) res += query((rt << 1 | 1), mid + 1, r, L, R);
  return res;
}
}  // namespace ST
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int x = read(), y = read();
    v[y].push_back((pair<int, int>){x, i});
  }
  for (int i = 1; i <= n; i++)
    if (!d[i]) tarjan(i, 0);
  sort(p + 1, p + cnt + 1);
  int j = 1, Max = 0;
  for (int i = 1; i <= n; i++) {
    while (j <= cnt && p[j].first <= i) Max = max(Max, p[j++].second);
    ST::change(1, 1, n, Max + 1, i);
    for (int j = 0; j < v[i].size(); j++)
      ans[v[i][j].second] = ST::query(1, 1, n, v[i][j].first, i);
  }
  for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
  return 0;
}
