#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
int dfn[MAXN] = {0}, vis[MAXN] = {0}, low[MAXN] = {0}, tot = 0,
    post[MAXN] = {0};
long long sum[MAXN];
stack<int> S;
vector<int> E[MAXN];
void tarjan(int par, int x) {
  low[x] = dfn[x] = ++tot;
  vis[x] = 1;
  S.push(x);
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (v == par) continue;
    if (!dfn[v]) {
      tarjan(x, v);
      low[x] = min(low[x], low[v]);
    } else if (vis[v])
      low[x] = min(low[x], dfn[v]);
  }
  if (low[x] == dfn[x]) {
    int mi = x, ma = x;
    while (1) {
      int now = S.top();
      S.pop();
      vis[now] = 0;
      mi = min(mi, now);
      ma = max(ma, now);
      if (now == x) break;
    }
    if (mi != ma) post[mi] = ma - 1;
  }
}
int main() {
  int n, m, u, v, l, r;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  memset(post, 0x3f, sizeof(post));
  for (int i = 1; i <= n; i++)
    if (dfn[i] == 0) tarjan(0, i);
  post[n] = n;
  for (int i = n - 1; i >= 1; i--) post[i] = min(post[i], post[i + 1]);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + post[i];
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &l, &r);
    int p = upper_bound(post + l, post + r, r) - post;
    long long ans = sum[p - 1] - sum[l - 1] + 1LL * r * (r - p + 1) -
                    1LL * (l + r - 2) * (r - l + 1) / 2;
    printf("%lld\n", ans);
  }
}
