#include <bits/stdc++.h>
using namespace std;
class document {
 private:
  char c;
  bool sign;

 public:
  document() {}
  template <typename T>
  void read(T &var) {
    var = 0;
    sign = 0;
    do {
      c = getchar();
      sign |= c == '-';
    } while (!isdigit(c));
    while (isdigit(c)) {
      var = var * 10 + c - '0';
      c = getchar();
    }
    if (sign) var = -var;
  }
} input;
const int maxn = 300100;
int n, m;
vector<int> v[maxn];
bool vis[maxn];
bool ins[maxn];
int par[maxn], belong[maxn], mn[maxn], mx[maxn], siz[maxn];
bool valid[maxn];
priority_queue<int, vector<int>, greater<int> > q;
void dfs(int p) {
  vis[p] = 1;
  ins[p] = 1;
  for (auto i : v[p]) {
    if (i == par[p]) continue;
    if (ins[i]) {
      int cur = p, prev;
      mn[i] = mx[i] = i;
      do {
        belong[cur] = i;
        mn[i] = min(mn[i], cur);
        mx[i] = max(mx[i], cur);
        siz[i]++;
        prev = cur;
        cur = par[cur];
      } while (prev != i);
      valid[mx[i]] = true;
      q.push(mx[i]);
    }
    if (vis[i]) continue;
    par[i] = p;
    dfs(i);
  }
  ins[p] = 0;
}
int R[maxn];
long long sr[maxn];
int main() {
  input.read(n);
  input.read(m);
  int x, y;
  for (int i = 1; i <= m; i++) {
    input.read(x);
    input.read(y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  q.push(n + 1);
  valid[n + 1] = true;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  for (int i = 1; i <= n; i++) {
    int v;
    while (1) {
      v = q.top();
      if (!valid[v])
        q.pop();
      else
        break;
    }
    R[i] = v - 1;
    sr[i] = sr[i - 1] + R[i];
    int bl = belong[i];
    if (i == mn[bl]) {
      valid[mx[bl]] = false;
    }
  }
  int Q;
  input.read(Q);
  for (int i = 1; i <= Q; i++) {
    input.read(x);
    input.read(y);
    int l = x - 1, r = y;
    while (r > l) {
      int mid = (l + r + 1) >> 1;
      if (R[mid] <= y)
        l = mid;
      else
        r = mid - 1;
    }
    long long ans = -(long long)(x + y - 2) * (y - x + 1) / 2;
    ans += sr[l] - sr[x - 1];
    ans += (long long)(y - l) * y;
    printf("%I64d\n", ans);
  }
  return 0;
}
