#include <bits/stdc++.h>
using namespace std;
ofstream out("output.txt");
struct cyclevertexes {
  int min_num;
  int max_num;
  cyclevertexes() : min_num(0), max_num(0) {}
  cyclevertexes(int a, int b) : min_num(a), max_num(b) {}
  bool operator<(const cyclevertexes &c) const {
    if (min_num == c.min_num) return max_num < c.max_num;
    return min_num < c.min_num;
  }
};
vector<vector<int>> graph;
vector<int> color;
vector<bool> was;
vector<cyclevertexes> cycle;
stack<int> rec;
cyclevertexes get_cycle(int v) {
  int min_num = 1e9 - 10, max_num = -10, use_v = 0;
  while (!rec.empty() && color[rec.top()] == 1) {
    int t = rec.top();
    if (t == v) {
      ++use_v;
      if (use_v == 2) break;
    }
    rec.pop();
    min_num = min(min_num, t);
    max_num = max(max_num, t);
  }
  return cyclevertexes(min_num, max_num);
}
void dfs(int v, int p = -1) {
  rec.push(v);
  if (color[v] >= 2) {
    return;
  }
  if (color[v] == 1) {
    cycle.push_back(get_cycle(v));
    return;
  }
  color[v] = 1;
  for (int u : graph[v]) {
    if (u != p) dfs(u, v);
  }
  color[v] = 2;
  if (!rec.empty() && rec.top() == v) rec.pop();
}
long long binsearch(vector<long long> &L, long long l) {
  long long left = 0, right = (long long)L.size();
  while (right - left > 1) {
    long long middle = (left + right) / 2;
    if (L[middle] > l)
      right = middle;
    else
      left = middle;
  }
  return left;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  graph.resize(n);
  for (int i = 0; i < m; ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    graph[--from].push_back(--to);
    graph[to].push_back(from);
  }
  color.resize(n, 0);
  was.resize(n, false);
  for (int i = 0; i < n; ++i) dfs(i);
  vector<long long> fromposnum(n, 1e7);
  for (int i = 0; i < (int)cycle.size(); ++i) fromposnum[cycle[i].max_num] = i;
  vector<long long> L(n);
  int pos = 0, r = 0;
  while (r < n) {
    if (fromposnum[r] == 1e7) {
      L[r] = pos;
      ++r;
      continue;
    }
    pos = max(pos, cycle[fromposnum[r]].min_num + 1);
    L[r] = pos;
    ++r;
  }
  vector<long long> Lsums(n);
  Lsums[0] = L[0];
  for (int i = 1; i < n; ++i) Lsums[i] = Lsums[i - 1] + L[i];
  int query;
  scanf("%d", &query);
  for (int i = 0; i < query; ++i) {
    long long left, right;
    scanf("%lld%lld", &left, &right);
    --left;
    --right;
    long long M = max(left, min(binsearch(L, left), right));
    long long ans = (1LL - left) * (M - left + 1LL) +
                    (long long)(left + M) * (M - left + 1LL) / 2;
    ans += (M + 1LL + right) * (right - M) / 2 - (Lsums[right] - Lsums[M]) +
           (right - M);
    printf("%lld\n", ans);
  }
  return 0;
}
