#include <bits/stdc++.h>
using namespace std;
long long low[300010], depth[300010], timer, cyc;
vector<long long> a[300010], scc[300010];
stack<long long> stck;
bool vis[300010], sccs[300010];
void dfs(long long x, long long papa) {
  low[x] = depth[x] = timer++;
  stck.push(x);
  vis[x] = 1;
  long long nxt, i_visit = 0;
  for (long long i = 0; i < a[x].size(); ++i) {
    nxt = a[x][i];
    if (nxt == papa) continue;
    if (!vis[nxt]) {
      ++i_visit;
      dfs(nxt, x);
      low[x] = min(low[x], low[nxt]);
    } else {
      low[x] = min(low[x], depth[nxt]);
    }
  }
  if (papa == -1 && i_visit > 1) {
    sccs[x] = 1;
  }
  if (papa != -1 && low[x] >= depth[papa]) {
    if (papa != 0) sccs[papa] = 1;
    while (1) {
      nxt = stck.top();
      scc[cyc].push_back(nxt);
      stck.pop();
      if (nxt == x) break;
    }
    scc[cyc].push_back(papa);
    ++cyc;
  }
}
long long nxt[300010], ans[300010];
long long tre1[300010 * 4], tre2[300010 * 4], lf, rt, val;
void updt1(int x, int st, int nd) {
  if (st > rt || nd < lf) return;
  if (st >= lf && nd <= rt) {
    tre1[x] += val;
    return;
  }
  int md;
  md = (st + nd) / 2;
  updt1(x * 2, st, md);
  updt1(x * 2 + 1, md + 1, nd);
}
long long qry1(int x, int st, int nd) {
  if (st > rt || nd < lf) return 0;
  if (st == nd) return tre1[x];
  int md;
  md = (st + nd) / 2;
  return qry1(x * 2, st, md) + qry1(x * 2 + 1, md + 1, nd) + tre1[x];
}
void updt2(int x, int st, int nd) {
  if (st > rt || nd < lf) return;
  if (st >= lf && nd <= rt) {
    tre2[x] += val;
    return;
  }
  int md;
  md = (st + nd) / 2;
  updt2(x * 2, st, md);
  updt2(x * 2 + 1, md + 1, nd);
}
long long qry2(int x, int st, int nd) {
  if (st > rt || nd < lf) return 0;
  if (st == nd) return tre2[x];
  int md;
  md = (st + nd) / 2;
  return qry2(x * 2, st, md) + qry2(x * 2 + 1, md + 1, nd) + tre2[x];
}
vector<long long> v[300010], b[300010];
long long s[300010], e[300010];
int main() {
  long long t, n, m, x, y, res, q;
  scanf("%lld %lld", &n, &m);
  for (long long i = 0; i < n; ++i) {
    a[i].clear();
    scc[i].clear();
  }
  for (long long i = 0; i < m; ++i) {
    scanf("%lld %lld", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  memset(vis, 0, sizeof vis);
  memset(sccs, 0, sizeof sccs);
  timer = 0;
  cyc = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) dfs(i, -1);
  }
  for (int i = 1; i <= n; ++i) {
    nxt[i] = n + 1;
  }
  long long mn, mx;
  for (long long i = 0; i < cyc; ++i) {
    if (scc[i].size() < 3) continue;
    mn = mx = scc[i][0];
    for (long long j = 0; j < scc[i].size(); ++j) {
      mn = min(mn, scc[i][j]);
      mx = max(mx, scc[i][j]);
    }
    nxt[mn] = mx;
  }
  for (int i = n - 1; i >= 1; --i) {
    nxt[i] = min(nxt[i], nxt[i + 1]);
    b[nxt[i]].push_back(i);
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    scanf("%lld %lld", &s[i], &e[i]);
    v[e[i]].push_back(i);
  }
  long long tmp1, tmp2, tmp;
  for (long long i = 1; i <= n; ++i) {
    lf = 1;
    rt = i;
    val = 1;
    updt1(1, 1, 300000);
    val = i;
    updt2(1, 1, 300000);
    for (int j = 0; j < b[i].size(); ++j) {
      lf = 1;
      rt = b[i][j];
      val = -1;
      updt1(1, 1, 300000);
      val = -b[i][j];
      updt2(1, 1, 300000);
      lf = 1;
      rt = b[i][j];
      val = -(i - b[i][j]);
      updt2(1, 1, 300000);
    }
    lf = rt = 4;
    for (long long j = 0; j < v[i].size(); ++j) {
      tmp = v[i][j];
      lf = s[tmp];
      rt = s[tmp];
      tmp1 = qry1(1, 1, 300000);
      tmp2 = qry2(1, 1, 300000);
      ans[tmp] = (i + 1) * tmp1 - tmp2;
    }
  }
  for (int i = 0; i < q; ++i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
