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 MX = (1 << 19);
vector<pair<int, int> > v[MX];
int depth[MX], low[MX], timer;
set<int> active[MX];
stack<int> S;
vector<vector<int> > E;
int n, m;
void Pdfs(int x, int p) {
  depth[x] = low[x] = ++timer;
  for (auto pp : v[x]) {
    int nxt = pp.first, idx = pp.second;
    if (idx == p) continue;
    if (depth[nxt] > depth[x]) continue;
    if (depth[nxt] == 0) {
      Pdfs(nxt, idx);
      low[x] = min(low[x], low[nxt]);
      if (low[nxt] > depth[x]) continue;
      if (low[nxt] == depth[x]) {
        bool ok = 0;
        if (!S.empty())
          if (depth[S.top()] >= depth[nxt]) ok = 1;
        if (!ok) continue;
        E.push_back(vector<int>());
        E.back().clear();
        E.back().push_back(idx);
        while (!S.empty()) {
          if (depth[S.top()] < depth[nxt]) break;
          int x = S.top();
          S.pop();
          for (auto pp : active[x]) {
            E.back().push_back(pp);
          }
          active[x].clear();
        }
      }
      if (low[nxt] < depth[x]) {
        active[x].insert(idx);
      }
    } else {
      low[x] = min(low[x], depth[nxt]);
      active[x].insert(idx);
    }
  }
  if (depth[x] != low[x]) {
    S.push(x);
  } else
    active[x].clear();
}
long long tree[MX * 4], flag[MX * 4], add[MX * 4];
int st, en, V;
void push(int x, int a, int b) {
  if (flag[x] == 0) return;
  flag[x * 2] += flag[x];
  flag[x * 2 + 1] += flag[x];
  tree[x * 2] += flag[x] * ((a + b) / 2 - a + 1);
  ;
  tree[x * 2 + 1] += flag[x] * (b - (a + b) / 2);
  flag[x] = 0;
}
void update(int x, int a, int b) {
  if (st > b || en < a) return;
  if (a >= st && b <= en) {
    tree[x] += (b - a + 1);
    flag[x]++;
    return;
  }
  push(x, a, b);
  update(x * 2, a, (a + b) / 2);
  update(x * 2 + 1, (a + b) / 2 + 1, b);
  tree[x] = tree[x * 2] + tree[x * 2 + 1];
}
long long query(int x, int a, int b) {
  if (st > b || en < a) return 0;
  if (a >= st && b <= en) return tree[x];
  push(x, a, b);
  return query(x * 2, a, (a + b) / 2) + query(x * 2 + 1, (a + b) / 2 + 1, b);
}
long long ans[MX], R[MX];
vector<pair<int, int> > Queries[MX];
int A[MX], B[MX];
int main() {
  scanf("%d %d", &n, &m);
  for (int j = 1; j <= m; j++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v[a].push_back({b, j});
    v[b].push_back({a, j});
    A[j] = a, B[j] = b;
    R[j] = m;
  }
  R[m + 1] = m;
  for (int j = 1; j <= n; j++)
    if (depth[j] == 0) Pdfs(j, -1);
  R[n + 1] = n;
  for (int j = 1; j <= n; j++) R[j] = n;
  for (auto &pp : E) {
    int mn = n + 1, mx = 0;
    for (auto ee : pp) {
      mn = min(mn, min(A[ee], B[ee]));
      mx = max(mx, max(A[ee], B[ee]));
    }
    R[mn] = mx - 1;
  }
  for (int j = n; j; j--) R[j] = min(R[j], R[j + 1]);
  int QN;
  scanf("%d", &QN);
  for (int j = 1; j <= QN; j++) {
    int a, b;
    scanf("%d %d", &a, &b);
    Queries[a].push_back({b, j});
  }
  for (int j = n; j; j--) {
    st = j, en = R[j], V = 1;
    update(1, 1, n);
    for (auto pp : Queries[j])
      st = j, en = pp.first, ans[pp.second] = query(1, 1, n);
  }
  for (int j = 1; j <= QN; j++) printf("%lld\n", ans[j]);
}
