#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;
int n, m;
int c[N], to[N], pos[N];
long long su[N];
vector<int> g[N];
vector<int> s;
void dfs(int v) {
  s.push_back(v);
  pos[v] = (int)s.size() - 1;
  for (int i : g[v]) {
    if (!c[i]) {
      c[i] = c[v] ^ 3;
      dfs(i);
    } else {
      if (c[i] == c[v]) {
        int mn = min(i, v), mx = max(i, v);
        for (int j = max(pos[i], pos[v]); j >= min(pos[i], pos[v]); --j) {
          mn = min(mn, s[j]);
          mx = max(mx, s[j]);
        }
        to[mn] = min(to[mn], mx - 1);
      }
    }
  }
}
long long get(int l, int r) {
  if (l > r) {
    return 0;
  }
  return su[r] - su[l - 1];
}
long long get(int x) { return x * (x + 1ll) / 2; }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    to[i] = n;
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    if (!c[i]) {
      c[i] = 1;
      dfs(i);
    }
  }
  for (int i = n - 1; i >= 1; --i) {
    to[i] = min(to[i], to[i + 1]);
  }
  for (int i = 1; i <= n; ++i) {
    su[i] = su[i - 1] + (to[i] - i + 1);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    int lf = l, rg = r;
    while (rg - lf > 1) {
      int mid = (lf + rg) >> 1;
      if (to[mid] < r) {
        lf = mid;
      } else {
        rg = mid;
      }
    }
    if (to[lf] >= r) {
      printf("%lld\n", get(l, lf - 1) + get(r - lf + 1));
    } else {
      printf("%lld\n", get(l, rg - 1) + get(r - rg + 1));
    }
  }
  return 0;
}
