#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
vector<int> g[300100];
int col[300100];
bool used[300100];
int dfs(int v, int p = -1) {
  used[v] = true;
  bool end = false;
  for (int i = 0; i < (int)(g[v].size()); ++i) {
    int to = g[v][i];
    if (to == p) {
      continue;
    }
    if (used[to]) {
      col[v] = to;
      continue;
    }
    int res = dfs(to, v);
    if (res != -1) {
      col[v] = res;
    }
    if (res == v) {
      end = true;
    }
  }
  if (end) {
    col[v] = v;
  }
  return col[v] == v ? -1 : col[v];
}
int last[300100];
int fst[300100];
int a[300100];
long long s[300100];
vector<pair<int, int> > q[300100];
long long ans[300100];
int main() {
  ios::sync_with_stdio(false);
  int n = 300000, m = 300000;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < (int)(n); ++i) {
    col[i] = -1;
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (col[i] != -1) {
      last[col[i]] = i;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (col[i] != -1) {
      fst[col[i]] = i;
    }
  }
  int r = n;
  for (int i = n - 1; i >= 0; --i) {
    if (col[i] != -1 && i == fst[col[i]]) {
      r = min(r, last[col[i]]);
    }
    a[i] = r;
  }
  s[0] = 0;
  for (int i = 0; i < (int)(n); ++i) {
    s[i + 1] = s[i] + a[i];
  }
  int k;
  cin >> k;
  for (int i = 0; i < (int)(k); ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    ans[i] -= y * (long long)(y - 1) / 2 - x * (long long)(x - 1) / 2;
    q[y].push_back(make_pair(x, i));
  }
  int j = n;
  for (int i = n; i > 0; --i) {
    while (j && a[j - 1] >= i) {
      --j;
    }
    for (int t = 0; t < (int)(q[i].size()); ++t) {
      int ind = q[i][t].second;
      int l = q[i][t].first;
      if (l >= j) {
        ans[ind] += (long long)(i - l) * i;
      } else {
        ans[ind] += (long long)(i - j) * i + s[j] - s[l];
      }
    }
  }
  for (int i = 0; i < (int)(k); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
