#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 18;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
vector<int> conn[300050];
int par[300050];
int dep[300050];
int low[300050];
bool dchk[300050];
vector<pair<int, int> > Ve;
void DFS(int n) {
  dchk[n] = true;
  low[n] = dep[n];
  for (auto it : conn[n]) {
    if (par[n] == it) continue;
    if (dchk[it]) {
      low[n] = min(low[n], dep[it]);
      Ve.emplace_back(n, it);
      continue;
    }
    par[it] = n;
    dep[it] = dep[n] + 1;
    DFS(it);
    if (low[it] <= dep[n]) Ve.emplace_back(it, n);
    low[n] = min(low[n], low[it]);
  }
}
int r[300050];
int root(int x) { return (x == r[x]) ? x : (r[x] = root(r[x])); }
vector<int> Vl[300050];
vector<pair<int, int> > Vu;
int mx[300050];
long long sum[300050];
int main() {
  int N, M, i, j;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= M; i++) {
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    conn[t1].push_back(t2);
    conn[t2].push_back(t1);
  }
  for (i = 1; i <= N; i++)
    if (!dchk[i]) DFS(i);
  for (i = 1; i <= N; i++) r[i] = i;
  for (auto it : Ve) r[root(it.first)] = root(it.second);
  for (i = 1; i <= N; i++) Vl[root(i)].push_back(i);
  for (i = 1; i <= N; i++) mx[i] = N;
  for (i = 1; i <= N; i++) {
    if (Vl[i].size() <= 1) continue;
    mx[Vl[i][0]] = min(mx[Vl[i][0]], Vl[i].back() - 1);
  }
  for (i = N - 1; i >= 1; i--) mx[i] = min(mx[i], mx[i + 1]);
  for (i = 1; i <= N; i++) sum[i] = sum[i - 1] + mx[i];
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    int st = t1, en = t2, mi, rv = t1 - 1;
    while (st <= en) {
      mi = (st + en) / 2;
      if (mx[mi] <= t2) {
        rv = mi;
        st = mi + 1;
      } else
        en = mi - 1;
    }
    long long s1 = sum[rv] - sum[t1 - 1] + (long long)t2 * (t2 - rv);
    long long s2 = (long long)(t1 + t2) * (t2 - t1 + 1) / 2 - (t2 - t1 + 1);
    printf("%lld\n", s1 - s2);
  }
  return 0;
}
