#include <bits/stdc++.h>
using namespace std;
struct qu {
  int first, second, id;
  qu(int l, int r, int i) {
    first = l;
    second = r;
    id = i;
  }
};
const int N = 3e5 + 5;
long long ans[N];
int n, m;
vector<int> v[N];
bool was[N];
vector<vector<int> > c;
vector<pair<int, int> > seg;
vector<qu> query;
int p[N];
int b[N];
int q[N];
long long pref[N];
bool mark[N];
void dfs(int i) {
  was[i] = true;
  for (int j : v[i]) {
    if (was[j] && p[i] != j && !mark[i]) {
      int cur = i;
      vector<int> w;
      while (cur != p[j]) {
        mark[cur] = true;
        w.push_back(cur);
        cur = p[cur];
      }
      c.push_back(w);
    } else if (!was[j]) {
      p[j] = i;
      dfs(j);
    }
  }
}
bool cmp(qu &a, qu &b) { return a.second < b.second; }
long long sum(long long n) { return n * (n + 1) / 2; }
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  fill(mark, mark + n, false);
  fill(was, was + n, false);
  for (int i = 0; i < n; i++)
    if (!was[i]) {
      p[i] = -1;
      dfs(i);
    }
  for (int i = 0; i < c.size(); i++) {
    int mn = n + 1;
    int mx = -1;
    for (int j : c[i]) {
      mn = min(mn, j);
      mx = max(mx, j);
    }
    seg.push_back(make_pair(mn, mx));
  }
  sort(seg.begin(), seg.end());
  q[seg.size()] = n;
  for (int i = (int)seg.size() - 1; i >= 0; i--)
    q[i] = min(q[i + 1], seg[i].second);
  for (int i = 0; i < n; i++) {
    int k = lower_bound(seg.begin(), seg.end(), make_pair(i, -1)) - seg.begin();
    b[i] = q[k];
  }
  int o;
  cin >> o;
  for (int i = 0; i < o; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    query.push_back(qu(l, r, i));
  }
  sort(query.begin(), query.end(), cmp);
  pref[0] = 0;
  int l = 0;
  for (qu &cur : query) {
    while (l <= cur.second && b[l] <= cur.second) {
      pref[l + 1] = pref[l] + b[l] - l;
      l++;
    }
    long long f = 0;
    if (l >= cur.first) f += pref[l] - pref[cur.first];
    f += sum(cur.second - max(cur.first, l) + 1);
    ans[cur.id] = f;
  }
  for (int i = 0; i < o; i++) cout << ans[i] << endl;
  return 0;
}
