#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
vector<int> adj[N];
int cycle[N], ma[N], mi[N], dp[N], cn = -1, n;
bool vis[N], ins[N];
vector<int> st;
long long bit1[N], bit2[N], ans[N];
void update1(int ind, long long val) {
  if (ind == 0) return;
  while (ind <= n && ind > 0) {
    bit1[ind] += val;
    ind += (ind & -ind);
  }
}
long long query1(int ind) {
  long long sum = 0;
  while (ind > 0) {
    sum += bit1[ind];
    ind -= (ind & -ind);
  }
  return sum;
}
void update2(int ind, long long val) {
  if (ind == 0) return;
  while (ind <= n && ind > 0) {
    bit2[ind] += val;
    ind += (ind & -ind);
  }
}
long long query2(int ind) {
  long long sum = 0;
  while (ind > 0) {
    sum += bit2[ind];
    ind -= (ind & -ind);
  }
  return sum;
}
void dfs(int s, int p) {
  if (vis[s]) return;
  vis[s] = true;
  ins[s] = true;
  st.push_back(s);
  for (auto it : adj[s]) {
    if (ins[it] && it != p) {
      cn++;
      while (st.size() > 0) {
        int x = st.back();
        cycle[x] = cn;
        ins[x] = false;
        ma[cn] = max(ma[cn], x);
        mi[cn] = min(mi[cn], x);
        st.pop_back();
        if (x == it) break;
      }
    }
    dfs(it, s);
  }
  ins[s] = false;
}
vector<pair<pair<int, int>, int> > qu;
int main() {
  int m, qn, i, x, y;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (i = 0; i < N; i++) {
    ma[i] = 0;
    mi[i] = 1e9;
    cycle[i] = -1;
  }
  for (i = 1; i <= n; i++) dfs(i, -1);
  dp[n] = n;
  for (i = n - 1; i > 0; i--) {
    dp[i] = dp[i + 1];
    if (i == mi[cycle[i]]) {
      dp[i] = min(dp[i], ma[cycle[i]] - 1);
    }
  }
  scanf("%d", &qn);
  int l, r;
  for (i = 0; i < qn; i++) {
    scanf("%d%d", &l, &r);
    qu.push_back({{r, l}, i});
  }
  sort(qu.begin(), qu.end());
  i = 1;
  for (auto it : qu) {
    l = it.first.second;
    r = it.first.first;
    int ind = it.second;
    while (i <= n && dp[i] <= r) {
      update1(i, dp[i]);
      update2(i, 1);
      i++;
    }
    long long sum = query1(r) - query1(l - 1);
    long long cnt = query2(r) - query2(l - 1);
    long long x = r - l + 1;
    long long ss = (1LL * r * (r + 1)) / 2 - (1LL * l * (l - 1)) / 2;
    ans[ind] = sum + (x - cnt) * r + x - ss;
  }
  for (i = 0; i < qn; i++) {
    printf("%lld\n", ans[i]);
  }
}
