#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, q, edgenum, top, sta[N], head[N], Next[N * 2], vet[N * 2], Nxt[N];
long long sum[N];
bool vis[N], vis2[N];
void add(int u, int v) {
  edgenum++;
  Next[edgenum] = head[u];
  vet[edgenum] = v;
  head[u] = edgenum;
}
void dfs(int u, int fa) {
  vis[u] = 1;
  sta[++top] = u;
  for (int e = head[u]; e; e = Next[e]) {
    int v = vet[e];
    if (v == fa) continue;
    if (!vis[v])
      dfs(v, u);
    else if (!vis2[v]) {
      int Max = 0, Min = n + 1;
      while (1) {
        int x = sta[top--];
        vis2[x] = 1;
        Max = max(Max, x), Min = min(Min, x);
        if (x == v) break;
      }
      Nxt[Min] = min(Nxt[Min], Max - 1);
    }
  }
  if (!vis2[u]) top--;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) Nxt[i] = n;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  for (int i = n - 1; i >= 1; i--) Nxt[i] = min(Nxt[i + 1], Nxt[i]);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + Nxt[i];
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int ql = l, qr = r;
    while (ql < qr) {
      int mid = (ql + qr + 1) >> 1;
      if (Nxt[mid] < r)
        ql = mid;
      else
        qr = mid - 1;
    }
    if (Nxt[ql] > r) ql--;
    printf("%lld\n", sum[ql] - sum[l - 1] + 1LL * (r - ql) * (r - ql + 1) / 2 -
                         1LL * (l + ql - 2) * (ql - l + 1) / 2);
  }
  return 0;
}
