#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const long long MAXN = 1e6 + 7;
const double EPS = 1e-8;
vector<vector<long long> > gr;
vector<bool> used;
vector<long long> segs;
vector<long long> add;
vector<long long> pred;
void dfs(long long v, long long p) {
  if (used[v] && !add[v]) {
    long long minv = v, maxv = v;
    long long u = p;
    add[v] = 1;
    while (u != v) {
      minv = min(minv, u);
      maxv = max(maxv, u);
      add[u] = 1;
      u = pred[u];
    }
    segs[minv] = maxv - 1;
  }
  if (used[v]) {
    return;
  }
  used[v] = 1;
  pred[v] = p;
  for (long long u : gr[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  gr.resize(n);
  add.resize(n, 0);
  used.resize(n, false);
  pred.resize(n, -1);
  segs.resize(n, n - 1);
  for (long long i = 0; i < m; i++) {
    long long v, u;
    cin >> v >> u;
    v--, u--;
    gr[v].push_back(u);
    gr[u].push_back(v);
  }
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      dfs(i, -1);
    }
  }
  for (long long i = n - 2; i >= 0; i--) {
    segs[i] = min(segs[i], segs[i + 1]);
  }
  vector<long long> pref(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    pref[i + 1] = pref[i] + segs[i] - i + 1;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    l--, r--;
    long long x = upper_bound(segs.begin() + l, segs.end(), r) - segs.begin();
    long long res = 0;
    if (x > r) {
      res += pref[r + 1] - pref[l];
    } else {
      res += pref[x] - pref[l];
      res += (r - x + 2) * (r - x + 1) / 2;
    }
    cout << res << "\n";
  }
}
