#include <bits/stdc++.h>
using namespace std;
long long n, m, u, v, q;
bool come[330000];
vector<long long> edge[330000];
long long parent[330000];
long long group[330000];
long long g_min[330000];
long long g_max[330000];
long long limit[330000];
long long l_sum[330000];
long long dep[330000];
void dfs(long long x, long long last = -1) {
  come[x] = true;
  for (auto to : edge[x]) {
    if (come[to]) {
      if (dep[to] < dep[x] - 1) {
        for (long long now = x;; now = parent[now]) {
          group[now] = x;
          if (now == to) break;
        }
      }
      continue;
    }
    parent[to] = x;
    dep[to] = dep[x] + 1;
    dfs(to, x);
  }
}
void calc() {
  for (long long i = 1; i <= n; i++) g_min[i] = n;
  for (long long i = 1; i <= n; i++) {
    if (!come[i]) dfs(i);
    g_min[group[i]] = min(g_min[group[i]], i);
    g_max[group[i]] = max(g_max[group[i]], i);
  }
  limit[0] = 1;
  set<long long> groups = {group[1]};
  for (long long i = 1; i <= n; i++) {
    limit[i] = limit[i - 1];
    long long &l = limit[i];
    while (true) {
      if (l == n ||
          (g_max[group[l + 1]] == l + 1 && groups.count(group[l + 1])))
        break;
      l++;
      if (g_min[group[l]] == l) groups.insert(group[l]);
    }
    l_sum[i] = l_sum[i - 1] + (l - i + 1);
    if (g_min[group[i]] == i) groups.erase(group[i]);
  }
}
void solve() {
  long long l, r;
  scanf("%lld%lld", &l, &r);
  long long bottom = l;
  long long top = r;
  if (limit[l] >= r) {
    top = l;
    bottom = l - 1;
  }
  while (top - bottom > 1) {
    long long mid = (bottom + top) / 2;
    if (limit[mid] >= r)
      top = mid;
    else
      bottom = mid;
  }
  long long ans = (r - top + 1) * (r - top + 2) / 2;
  ans += l_sum[bottom] - l_sum[l - 1];
  printf("%lld\n", ans);
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) group[i] = i;
  for (long long i = 0; i < m; i++) {
    scanf("%lld%lld", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  calc();
  scanf("%lld", &q);
  for (long long i = 0; i < q; i++) solve();
  return 0;
}
