#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 3e5 + 5;
int n, m, q;
vector<int> adj[maxn];
int vis[maxn];
int lev[maxn];
int from[maxn];
vector<pair<int, int> > vals;
void dfs(int u, int p) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (!vis[v]) {
      from[v] = u;
      lev[v] = lev[u] + 1;
      dfs(v, u);
    } else if (v != p && lev[v] < lev[u]) {
      int mn = INF, mx = -INF;
      int ptr = u;
      while (ptr != v) {
        chkmin(mn, ptr);
        chkmax(mx, ptr);
        ptr = from[ptr];
      }
      chkmin(mn, ptr);
      chkmax(mx, ptr);
      vals.push_back(make_pair(mn, mx));
    }
  }
}
long long fen[3][maxn];
void upd(long long fen[], int p, int val) {
  p++;
  for (; p < maxn; p += p & -p) {
    fen[p] += val;
  }
}
long long query(long long fen[], int p) {
  p++;
  long long res = 0;
  for (; p > 0; p -= p & -p) {
    res += fen[p];
  }
  return res;
}
void solve() {
  cin >> n >> m;
  for (int i = (0); i < (m); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  for (int i = (0); i < (n); i++)
    if (!vis[i]) dfs(i, -1);
  static int f[maxn];
  fill_n(f, n, n - 1);
  multiset<int> st;
  sort((vals).begin(), (vals).end());
  for (pair<int, int> p : vals) {
    st.insert(p.second);
  }
  int ptr = 0;
  for (int i = (0); i < (n); i++) {
    while (ptr < int((vals).size()) && vals[ptr].first < i) {
      st.erase(st.find(vals[ptr].second));
      ptr++;
    }
    if (int((st).size())) {
      f[i] = *st.begin() - 1;
    }
  }
  cin >> q;
  static vector<pair<int, int> > que[maxn];
  for (int i = (0); i < (q); i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    que[l].push_back(make_pair(r, i));
  }
  static long long res[maxn];
  for (int i = (n)-1; i >= (0); i--) {
    upd(fen[0], f[i], f[i] - i + 1);
    upd(fen[1], f[i], 1);
    upd(fen[2], f[i], i);
    for (pair<int, int> p : que[i]) {
      int r = p.first;
      int ix = p.second;
      res[ix] += query(fen[0], r);
      long long cnt = (r - i + 1) - query(fen[1], r);
      long long sum = (long long)(i + r) * (r - i + 1) / 2 - query(fen[2], r);
      res[ix] += cnt * (r + 1) - sum;
    }
  }
  for (int i = (0); i < (q); i++) cout << res[i] << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
