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;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
class UnionFind {
 private:
  vector<int> p;

 public:
  UnionFind(int n) {
    p.assign(n, 0);
    for (int i = 0; i < n; i++) {
      p[i] = i;
    }
  }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) {
      int x = findSet(i), y = findSet(j);
      p[y] = x;
    }
  }
};
vector<bool> vis;
vector<vector<int> > adj;
vector<vector<int> > pa;
vector<int> lv;
int sz = 20;
void dfs(int u, int parent, int lvl) {
  vis[u] = true;
  pa[u][0] = parent;
  lv[u] = lvl;
  for (int j = 0; j < (int)adj[u].size(); j++) {
    int v = adj[u][j];
    if (v != parent) {
      dfs(v, u, lvl + 1);
    }
  }
}
int lca(int x, int y) {
  if (lv[x] < lv[y]) swap(x, y);
  int g = lv[x] - lv[y];
  for (int j = sz - 1; j >= 0; j--) {
    if (g & (1 << j)) x = pa[x][j];
  }
  if (x == y) return x;
  for (int j = sz - 1; j >= 0; j--) {
    if (pa[x][j] != pa[y][j]) {
      x = pa[x][j];
      y = pa[y][j];
    }
  }
  return pa[x][0];
}
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<pair<int, int> > e;
  adj.assign(n, vector<int>());
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (!uf.isSameSet(x, y)) {
      adj[x].push_back(y);
      adj[y].push_back(x);
      uf.unionSet(x, y);
    } else {
      e.push_back(pair<int, int>(x, y));
    }
  }
  lv.assign(n, -1);
  pa.assign(n, vector<int>(20, -1));
  vis.assign(n, false);
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i, -1, 0);
    }
  }
  for (int j = 1; j < sz; j++) {
    for (int i = 0; i < n; i++) {
      if (pa[i][j - 1] != -1) {
        pa[i][j] = pa[pa[i][j - 1]][j - 1];
      }
    }
  }
  vector<pair<int, int> > seg;
  for (int i = 0; i < (int)e.size(); i++) {
    int u = e[i].first;
    int v = e[i].second;
    int r = lca(u, v);
    vector<int> t;
    while (u != r) {
      t.push_back(u);
      u = pa[u][0];
    }
    while (v != r) {
      t.push_back(v);
      v = pa[v][0];
    }
    t.push_back(r);
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    seg.push_back(pair<int, int>(t[0], t.back()));
  }
  sort(seg.begin(), seg.end());
  vector<pair<int, int> > st(2 * n + 10, pair<int, int>());
  int lp = 0, rp = 0;
  for (int i = 0; i < (int)seg.size(); i++) {
    while (rp > lp) {
      if (st[rp - 1].first >= seg[i].second)
        rp--;
      else
        break;
    }
    st[rp++] = pair<int, int>(seg[i].second, seg[i].first);
  }
  vector<int> rb(n, n);
  for (int i = 0; i < n; i++) {
    while (lp < rp) {
      if (st[lp].second < i)
        lp++;
      else
        break;
    }
    if (lp < rp) rb[i] = st[lp].first;
  }
  vector<long long> pre(n, 0);
  for (int i = 0; i < n; i++) {
    pre[i] = 1LL * rb[i];
    if (i) pre[i] += pre[i - 1];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    int low = l;
    int high = r;
    int ans = l - 1;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (rb[mid] <= r) {
        ans = mid;
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    long long re = 0LL;
    if (ans >= 0) re += pre[ans];
    if (l > 0) re -= pre[l - 1];
    re += 1LL * (r + 1) * (r - ans);
    re -= 1LL * (l + r) * (r - l + 1) / 2;
    cout << re << endl;
  }
  return 0;
}
