#include <bits/stdc++.h>
using namespace std;
const int mx = 3e5 + 5;
stack<int> s;
int front[mx];
vector<int> g[mx];
int pre[mx];
int Max[mx], Min[mx];
long long int sum[mx];
void dfs(int u, int fa) {
  pre[u] = 1;
  s.push(u);
  for (auto v : g[u]) {
    if (v != fa) {
      if (pre[v] == 0)
        dfs(v, u);
      else if (pre[v] == 1) {
        int x = u, y = u;
        while (!s.empty()) {
          int z = s.top();
          s.pop();
          x = min(z, x);
          y = max(z, y);
          if (z == v) break;
        }
        Max[y] = x;
        Min[x] = y;
      }
    }
  }
  if (!s.empty() && s.top() == u) s.pop();
  pre[u] = 2;
}
int main() {
  int n, m, q;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i <= n + 1; i++) Max[i] = 0, Min[i] = n + 1;
  for (int i = 1; i <= n; i++)
    if (!pre[i]) dfs(i, i);
  int x, y;
  for (int i = n; i >= 1; i--) {
    Min[i] = min(Min[i + 1], Min[i]);
    sum[i] = sum[i + 1] + Min[i] - i;
  }
  for (int i = 1; i <= n; i++) Max[i] = max(Max[i - 1], Max[i]);
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    x = max(l, Max[r] + 1);
    long long int ans = sum[l] - sum[x];
    ans += 1ll * (r - x + 2) * (r - x + 1) / 2;
    printf("%I64d\n", ans);
  }
  return 0;
}
