#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, q;
int p[N], st[N], dp[N];
long long sum[N];
vector<int> g[N];
int vis[N];
void cycle(int a, int x) {
  int l = n + 2, r = -1;
  l = min(l, x);
  r = max(r, x);
  while (x != a) {
    x = p[x];
    l = min(l, x);
    r = max(r, x);
  }
  st[l] = r;
}
void dfs(int x) {
  vis[x] = 1;
  for (auto it : g[x]) {
    if (!vis[it]) {
      p[it] = x;
      dfs(it);
    } else if (it != p[x] and vis[it] == 1) {
      cycle(it, x);
    }
  }
  vis[x] = 2;
}
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
    dp[i] = n;
  }
  dp[n] = n;
  for (int i = n - 1; i > 0; i--) {
    dp[i] = dp[i + 1];
    if (st[i] > 0) dp[i] = min(dp[i], st[i] - 1);
  }
  for (int i = 1; i <= n; i++) {
    dp[i] -= i;
    sum[i] = sum[i - 1] + dp[i];
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int l = a, r = b;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (dp[mid] + mid >= b)
        r = mid;
      else
        l = mid + 1;
    }
    long long ans = 0;
    ans += (1ll * (b - l + 1) * (b - l + 2)) / 2;
    ans += sum[l - 1] - sum[a - 1] + l - a;
    printf("%lld\n", ans);
  }
}
