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 mxn = 6e5 + 10;
int g[mxn], nxt[mxn], v[mxn], ed = 0;
void add(int x, int y) {
  v[++ed] = y;
  nxt[ed] = g[x];
  g[x] = ed;
}
vector<pair<long long, long long> > e;
int fa[300010];
int find(int x) { return fa[x] < 0 ? x : fa[x] = find(fa[x]); }
int size(int x) {
  find(x);
  return fa[x] < 0 ? -fa[x] : -fa[fa[x]];
}
void uni(int x, int y) {
  if (size(x) < size(y)) swap(x, y);
  x = fa[x] < 0 ? x : fa[x];
  y = fa[y] < 0 ? y : fa[y];
  fa[x] += fa[y];
  fa[y] = x;
}
int f[300010][20], deep[300010];
void dfs(int x) {
  deep[x] = deep[f[x][0]] + 1;
  for (int i = 0; f[x][i]; i++) f[x][i + 1] = f[f[x][i]][i];
  for (int i = g[x]; i; i = nxt[i]) {
    if (!deep[v[i]]) f[v[i]][0] = x, dfs(v[i]);
  }
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (deep[f[x][i]] >= deep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
pair<long long, long long> findm(long long x, long long a,
                                 pair<long long, long long> ret) {
  if (x == a) return {min(ret.first, x), max(ret.second, x)};
  return findm(f[x][0], a, {min(ret.first, x), max(ret.second, x)});
}
vector<pair<long long, long long> > c, C;
bool cmpr(const pair<long long, long long>& a,
          const pair<long long, long long>& b) {
  return a.second < b.second;
}
bool cmpl(const pair<long long, long long>& a,
          const pair<long long, long long>& b) {
  return a.first < b.first;
}
pair<long long, long long> T[100000 * 4];
void build(int l, int r, int rt) {
  if (l == r) {
    T[rt].first = c[l].first - c[l - 1].first;
    T[rt].second = T[rt].first * c[l].second - T[rt].first;
    return;
  }
  build(l, (l + r) / 2, rt << 1);
  build((l + r) / 2 + 1, r, rt << 1 | 1);
  T[rt].first = T[rt << 1 | 1].first + T[rt << 1].first;
  T[rt].second = T[rt << 1 | 1].second + T[rt << 1].second;
}
long long query(int l, int r, int rt, int L, int R, int x) {
  if (l >= L && r <= R) return x * T[rt].first - T[rt].second;
  long long ret = 0;
  if ((l + r) / 2 >= L) ret += query(l, (l + r) / 2, rt << 1, L, R, x);
  if ((l + r) / 2 + 1 <= R)
    ret += query((l + r) / 2 + 1, r, rt << 1 | 1, L, R, x);
  return ret;
}
int main() {
  int n, m;
  memset(fa, -1, sizeof(fa));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (find(u) == find(v)) {
      e.push_back({u, v});
    } else {
      add(u, v);
      add(v, u);
      uni(u, v);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (deep[i] == 0) dfs(i);
  };
  for (int i = 0; i < (int)(e).size(); i++) {
    int a = lca(e[i].first, e[i].second);
    pair<long long, long long> ret1 =
        findm(e[i].first, a, {(int)1e9, (int)-1e9});
    pair<long long, long long> ret2 =
        findm(e[i].second, a, {(int)1e9, (int)-1e9});
    C.push_back({min(ret1.first, ret2.first), max(ret1.second, ret2.second)});
  };
  sort(C.begin(), C.end());
  c.push_back({0, 0});
  for (int i = 0; i < (int)(C).size(); i++) {
    while (C[i].second < c[(int)(c).size() - 1].second) {
      c.erase(c.end() - 1);
    }
    c.push_back(C[i]);
  };
  int cs = (int)(c).size() - 1;
  if (cs >= 1) build(1, cs, 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    long long res = (r - l + 1) * (r - l) / 2 + (r - l + 1);
    auto L = lower_bound(c.begin(), c.end(), (pair<long long, long long>){l, 0},
                         cmpl);
    auto R = upper_bound(c.begin(), c.end(), (pair<long long, long long>){0, r},
                         cmpr);
    if (R > L) {
      res -= ((*L).first - l + 1) * (r - (*L).second + 1);
      if (R - 1 > L) {
        res -= query(1, cs, 1, (int)(L - c.begin() + 1),
                     (int)(R - c.begin() - 1), r);
      }
    }
    cout << res << endl;
  }
  return 0;
}
