#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 3e5 + 7;
const int M = 1e6 + 7;
int dfn[N], low[N], sccno[N], scc, times;
int mx[N], mn[N], s[N], siz[N];
long long sum[N];
vector<int> G[N];
stack<int> st;
void dfs(int u, int fa) {
  dfn[u] = low[u] = ++times;
  st.push(u);
  for (int v : G[u]) {
    if (v == fa) continue;
    if (!dfn[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
    } else if (!sccno[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    scc++;
    while (1) {
      siz[scc]++;
      int x = st.top();
      st.pop();
      sccno[x] = scc;
      if (x == u) break;
    }
  }
}
signed main() {
  int n, m, q, u, v;
  scanf("%d", &n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &u);
    scanf("%d", &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i, 0);
  for (int i = 1; i <= n; i++) mx[sccno[i]] = i, s[i] = n;
  for (int i = n; i; i--) mn[sccno[i]] = i;
  for (int i = 1; i <= scc; i++)
    if (siz[i] > 1) s[mn[i]] = mx[i] - 1;
  for (int i = n - 1; i; i--) s[i] = min(s[i], s[i + 1]);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + s[i] - i + 1;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &u);
    scanf("%d", &v);
    int p = lower_bound(s + u, s + v + 1, v) - s;
    long long ans = 0ll;
    ans += sum[p - 1] - sum[u - 1];
    ans += (long long)(v - p + 1ll) * (long long)(v - p + 2ll) / 2ll;
    printf("%lld\n", ans);
  }
  return 0;
}
