#include <bits/stdc++.h>
using namespace std;
vector<int> empty, hd, mark, cyc, sum;
vector<vector<int> > dis;
vector<long long> seg;
vector<pair<int, int> > G, _dis;
void add(int u, int v) {
  G.push_back(make_pair(v, hd[u]));
  hd[u] = G.size() - 1;
}
bool trav(int x, int t, int &ill, int p) {
  int i, tmpv, j;
  mark[x] = t;
  for (i = hd[x]; ~i; i = G[i].second) {
    j = G[i].first;
    if (j == p || cyc[j] == x) continue;
    if (mark[j]) {
      if (mark[j] == mark[x]) {
        ill = j;
        dis.back().push_back(x);
        cyc[x] = j;
      }
    } else {
      tmpv = -1;
      if (!trav(j, 3 ^ t, tmpv, x)) {
        dis.back().push_back(x);
        if (tmpv != x)
          ill = tmpv, cyc[x] = tmpv;
        else {
          dis.push_back(empty);
        }
      }
    }
  }
  if (ill == -1)
    return true;
  else
    return false;
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  int n, m, i, l, r, tmpv, q, u, v, x, y, tmp, mn, mx, j, mid, k;
  long long ans;
  scanf("%d%d", &n, &m);
  hd.clear();
  for (i = 0; i < n; i++) hd.push_back(-1);
  G.clear();
  while (m--) {
    scanf("%d%d", &u, &v);
    add(u - 1, v - 1);
    add(v - 1, u - 1);
  }
  mark.clear();
  cyc.clear();
  for (i = 0; i < n; i++) mark.push_back(0), cyc.push_back(-1);
  dis.clear();
  empty.clear();
  dis.push_back(empty);
  for (i = 0; i < n; i++) {
    tmpv = -1;
    if (!mark[i]) {
      trav(i, 1, tmpv, -1);
    }
  }
  dis.pop_back();
  _dis.clear();
  for (i = dis.size() - 1; ~i; i--) {
    mn = mx = dis[i][0];
    for (j = 1; j < dis[i].size(); j++) {
      if (dis[i][j] < mn) mn = dis[i][j];
      if (dis[i][j] > mx) mx = dis[i][j];
    }
    _dis.push_back(make_pair(mn, mx));
  }
  sort(_dis.begin(), _dis.end(), cmp);
  sum.clear();
  for (k = 0, j = 0, i = 0; i < n; i++) {
    for (; k < _dis.size() && _dis[k].second == i;) {
      j = max(j, _dis[k].first + 1);
      k++;
    }
    sum.push_back(j);
  }
  seg.clear();
  for (i = 0; i < n; i++) seg.push_back(sum[i]);
  for (i = 0; i < n; i++) seg[i] = i - seg[i] + 1;
  for (i = 1; i < n; i++) seg[i] += seg[i - 1];
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &x, &y);
    x--, y--;
    for (l = x, r = y; l != r;) {
      mid = (l + r + 1) / 2;
      if (sum[mid] <= x)
        l = mid;
      else
        r = mid - 1;
    }
    ans = seg[y] - seg[l];
    tmp = l - x + 1;
    ans += (1LL + tmp) * tmp / 2;
    printf("%lld\n", ans);
  }
  return 0;
}
