#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 77, Mod = 1e9 + 7;
int n, m, par[N], R[N], h[N], q, l, r;
long long ps[N];
vector<int> a[N];
bool M[N];
void dfs(int v) {
  M[v] = true;
  for (int u : a[v]) {
    if (M[u] && h[u] < h[v] && par[v] != u) {
      int x = v, Mx = v, Mn = v;
      while (x != u) {
        x = par[x];
        Mn = min(Mn, x);
        Mx = max(Mx, x);
      }
      R[Mn] = min(R[Mn], Mx);
    }
    if (M[u]) continue;
    par[u] = v;
    h[u] = h[v] + 1;
    dfs(u);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) R[i] = n + 1;
  R[n + 1] = n + 2;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!M[i]) dfs(i);
  for (int i = n - 1; i > 0; i--) R[i] = min(R[i], R[i + 1]);
  for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + R[i] - i;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &l, &r);
    int x = (lower_bound(R + l, R + r + 1, r + 1) - R);
    printf("%I64d\n",
           -ps[l - 1] + ps[x - 1] + ((r - x + 1) * 1ll * (r - x + 2) / 2));
  }
}
