#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const int SQ = 550;
vector<int> v[maxn];
vector<pair<int, int> > sg;
long long ans[maxn];
pair<pair<int, int>, int> qu[maxn];
bool mark[maxn];
int h[maxn], par[maxn], dp[maxn], dd[maxn];
void dfs(int x, int p) {
  mark[x] = true;
  par[x] = p;
  for (int i = 0; i < v[x].size(); i++) {
    int child = v[x][i];
    if (!mark[child]) {
      h[child] = h[x] + 1;
      dfs(child, x);
    } else if (child != p and h[x] > h[child]) {
      int cur = x, minn = x, maxx = x;
      while (cur != child) {
        cur = par[cur];
        minn = min(minn, cur);
        maxx = max(maxx, cur);
      }
      sg.push_back(make_pair(minn, maxx));
    }
  }
}
bool cmp(pair<pair<int, int>, int> fi, pair<pair<int, int>, int> se) {
  return make_pair(fi.first.second, fi.first.first) <
         make_pair(se.first.second, se.first.first);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int fi, se;
    cin >> fi >> se;
    v[fi].push_back(se);
    v[se].push_back(fi);
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i]) dfs(i, -1);
  }
  sort(sg.begin(), sg.end());
  reverse(sg.begin(), sg.end());
  memset(dd, 63, sizeof dd);
  int cnt = 0, mx = n + 1;
  for (int i = n; i >= 1; i--) {
    while (cnt < sg.size() and sg[cnt].first == i) {
      mx = min(mx, sg[cnt].second);
      cnt++;
    }
    dp[i] = mx - 1;
    dd[dp[i]] = min(dd[dp[i]], i);
  }
  for (int i = n - 1; i >= 1; i--) dd[i] = min(dd[i], dd[i + 1]);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> qu[i].first.first >> qu[i].first.second;
    qu[i].second = i;
  }
  sort(qu, qu + q);
  int ptrl = 0;
  while (ptrl < q) {
    int ptrr = ptrl;
    while (ptrr < q and
           qu[ptrl].first.first / SQ == qu[ptrr].first.first / SQ) {
      ptrr++;
    }
    sort(qu + ptrl, qu + ptrr, cmp);
    int l = qu[ptrl].first.first;
    int r = qu[ptrl].first.second + 1;
    long long cur = 0;
    for (int i = l; i < r; i++) cur += min(r - 1, dp[i]) - i + 1;
    for (int i = ptrl; i < ptrr; i++) {
      while (l < qu[i].first.first) {
        cur -= min(dp[l] - l + 1, r - l);
        l++;
      }
      while (l > qu[i].first.first) {
        l--;
        cur += min(dp[l] - l + 1, r - l);
      }
      while (r <= qu[i].first.second) {
        cur += min(r - dd[r] + 1, r - l + 1);
        r++;
      }
      ans[qu[i].second] = cur;
    }
    ptrl = ptrr;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
}
