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;
const int N = 3e5 + 10, K = 20;
struct edge {
  int x, y;
} a[N];
int to[N << 1], fs[N], nx[N << 1], e = 1;
int vis[N], c[N << 1];
int dep[N], fa[N][K];
inline void add(int x, int y) {
  to[++e] = y;
  nx[e] = fs[x];
  fs[x] = e;
}
void init(int x, int f) {
  dep[x] = dep[f] + 1;
  fa[x][0] = f;
  for (int i = 1; i <= 18; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = fs[x]; i; i = nx[i]) {
    int k = to[i];
    if (vis[k] || k == f) continue;
    vis[k] = c[i >> 1] = 1;
    init(k, x);
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 18; ~i; --i)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 18; ~i; --i)
    if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int nxt[N];
struct ask {
  int num, x, y, tp;
};
vector<ask> que[N];
long long val[N << 2], tag[N << 2];
inline void update(int r, int x, int y) {
  if (!tag[r]) return;
  int m = (x + y) >> 1;
  val[r << 1] += tag[r] * (m - x + 1);
  val[r << 1 | 1] += tag[r] * (y - m);
  tag[r << 1] += tag[r];
  tag[r << 1 | 1] += tag[r];
  tag[r] = 0;
}
void add(int r, int x, int y, int u, int v, int p) {
  if (u <= x && y <= v) {
    val[r] += p * (y - x + 1);
    tag[r] += p;
    return;
  }
  update(r, x, y);
  int m = (x + y) >> 1;
  if (u <= m) add(r << 1, x, m, u, v, p);
  if (m < v) add(r << 1 | 1, m + 1, y, u, v, p);
  val[r] = val[r << 1] + val[r << 1 | 1];
}
long long query(int r, int x, int y, int u, int v) {
  if (u <= x && y <= v) return val[r];
  update(r, x, y);
  int m = (x + y) >> 1;
  long long res = 0;
  if (u <= m) res += query(r << 1, x, m, u, v);
  if (m < v) res += query(r << 1 | 1, m + 1, y, u, v);
  return res;
}
long long ans[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = (edge){x, y};
    add(x, y), add(y, x);
  }
  for (int x = 1; x <= n; ++x)
    if (!vis[x]) vis[x] = 1, init(x, 0);
  for (int i = 1; i <= n; ++i) nxt[i] = n;
  for (int i = 1; i <= m; ++i) {
    if (c[i]) continue;
    int x = a[i].x, y = a[i].y;
    int t = lca(x, y);
    vector<int> vec;
    while (x ^ t) vec.push_back(x), x = fa[x][0];
    while (y ^ t) vec.push_back(y), y = fa[y][0];
    vec.push_back(t);
    sort(vec.begin(), vec.end());
    nxt[vec[0]] = vec[vec.size() - 1] - 1;
  }
  for (int i = n - 1; i; --i) nxt[i] = min(nxt[i], nxt[i + 1]);
  int p;
  scanf("%d", &p);
  for (int i = 1; i <= p; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > 1) que[x - 1].push_back((ask){i, x, y, -1});
    que[y].push_back((ask){i, x, y, 1});
  }
  for (int i = 1; i <= n; ++i) {
    add(1, 1, n, i, nxt[i], 1);
    for (int k = 0; k < que[i].size(); ++k) {
      int num = que[i][k].num;
      int x = que[i][k].x, y = que[i][k].y, tp = que[i][k].tp;
      ans[num] += tp * query(1, 1, n, x, y);
    }
  }
  for (int i = 1; i <= p; ++i) printf("%lld\n", ans[i]);
  return 0;
}
