#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 3e5 + 5, inf = 1e9;
vector<int> f;
pair<int, int> e[N];
vector<int> g[N];
int used[N];
vector<pair<int, int>> s;
void go(int v, int p = -1) {
  used[v] = 2;
  for (int k : g[v]) {
    int i = e[k].first ^ e[k].second ^ v;
    if (i == p) continue;
    if (!used[i]) {
      s.push_back({i, k});
      go(i, v);
      s.pop_back();
    } else if (used[i] == 2) {
      int mn = i, mx = i;
      auto it = s.end();
      --it;
      for (;;) {
        if (it->first == i) break;
        mn = min(mn, it->first);
        mx = max(mx, it->first);
        --it;
      }
      f[mn] = mx;
    }
  }
  used[v] = 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int k = 0; k < m; ++k) {
    cin >> e[k].first >> e[k].second;
    --e[k].first;
    --e[k].second;
    g[e[k].first].push_back(k);
    g[e[k].second].push_back(k);
  }
  f.assign(n, n);
  for (int i = 0; i < n; ++i)
    if (!used[i]) {
      s = {{i, -1}};
      go(i);
    }
  for (int i = n - 2; i >= 0; --i) f[i] = min(f[i], f[i + 1]);
  for (int x : f) cerr << x << ' ';
  cerr << endl;
  vector<ll> sg;
  for (int x : f) sg.push_back(x);
  for (int k = 1; k < n; ++k) sg[k] += sg[k - 1];
  int qn;
  cin >> qn;
  while (qn--) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    int k = r + 1;
    int i = upper_bound(f.begin() + l, f.begin() + r + 1, k) - f.begin();
    ll b = r + 1 - i;
    ll a = 0;
    if (i > l) {
      --i;
      a = sg[i];
      if (l) a -= sg[l - 1];
    }
    ll sumi = (l + r) * (r - l + 1LL) / 2;
    ll res = a + b * (r + 1) - sumi;
    cout << res << '\n';
  }
  return 0;
}
