#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, siz = 1e6 + 5;
vector<long long> g[siz];
long long n, t, m, k, a[siz], sum[siz], l[siz], vis[siz];
stack<long long> st;
void go(long long u, long long p) {
  vis[u] = 1;
  st.push(u);
  for (auto v : g[u]) {
    if (v == p) continue;
    if (!vis[v])
      go(v, u);
    else if (vis[v] == 1) {
      long long mn = v, mx = v;
      while (st.top() != v) {
        mn = min(mn, st.top());
        mx = max(mx, st.top());
        st.pop();
      }
      l[mx] = mn;
      st.pop();
    }
  }
  if (st.size() and st.top() == u) st.pop();
  vis[u] = 2;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) go(i, 0);
  for (long long i = 1; i <= n; i++) {
    l[i] = max(l[i - 1], l[i]);
    sum[i] = sum[i - 1] + i - l[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long lft, rit;
    cin >> lft >> rit;
    long long pos_left = lower_bound(l + lft, l + 1 + rit, lft) - l;
    long long ans = (pos_left - lft) * (pos_left - lft + 1) / 2;
    ans += sum[rit] - sum[pos_left - 1];
    cout << ans << endl;
  }
}
