#include <bits/stdc++.h>
using namespace std;
const int M = 300100, mod = 1000000007;
vector<int> A[M];
int visited[M];
stack<int> S;
int L[M];
void dfs(int u, int p) {
  S.push(u);
  visited[u] = 1;
  for (int v : A[u]) {
    if (visited[v] == 0)
      dfs(v, u);
    else if (visited[v] == 1 && v != p) {
      int maxx = 0, minn = 1000000011;
      while (!S.empty()) {
        int w = S.top();
        S.pop();
        minn = min(minn, w);
        maxx = max(maxx, w);
        if (w == v) break;
      }
      L[maxx] = max(L[maxx], minn);
    }
  }
  if (!S.empty() && S.top() == u) S.pop();
  visited[u] = 2;
}
struct segment_tree {
  long long lazy[4 * M], sum[4 * M];
  segment_tree() {
    memset((lazy), (0), sizeof(lazy));
    memset((sum), (0), sizeof(sum));
  }
  long long __value(int i, int l, int r) {
    return sum[i] + lazy[i] * (r - l + 1);
  }
  void __propagate(int i, int l, int r) {
    sum[i] += lazy[i] * (r - l + 1);
    if (l != r) lazy[2 * i] += lazy[i], lazy[2 * i + 1] += lazy[i];
    lazy[i] = 0;
  }
  void update(int i, int l, int r, int st, int ed, int val) {
    __propagate(i, l, r);
    if (l >= st && r <= ed)
      lazy[i] += val;
    else if (l > ed || r < st)
      return;
    else {
      int m = (l + r) / 2;
      update(2 * i, l, m, st, ed, val);
      update(2 * i + 1, m + 1, r, st, ed, val);
      sum[i] = __value(2 * i, l, m) + __value(2 * i + 1, m + 1, r);
    }
  }
  long long query(int i, int l, int r, int st, int ed) {
    __propagate(i, l, r);
    if (l >= st && r <= ed)
      return sum[i];
    else if (l > ed || r < st)
      return 0;
    else {
      int m = (l + r) / 2;
      return query(2 * i, l, m, st, ed) + query(2 * i + 1, m + 1, r, st, ed);
    }
  }
};
segment_tree seg;
vector<pair<int, int> > qq[M];
long long ans[M];
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k;
  int n, m;
  int q, l, r;
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d", &i, &j);
    A[i].push_back(j);
    A[j].push_back(i);
  }
  for (i = 1; i <= n; i++)
    if (visited[i] == 0) dfs(i, -1);
  int maxx = 0;
  for (i = 1; i <= n; i++) {
    maxx = max(maxx, L[i]);
    L[i] = maxx + 1;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &l, &r);
    qq[r].push_back(make_pair(l, i));
  }
  for (i = 1; i <= n; i++) {
    seg.update(1, 1, n, L[i], i, 1);
    for (pair<int, int> p : qq[i]) {
      int l = p.first;
      int id = p.second;
      ans[id] = seg.query(1, 1, n, l, i);
    }
  }
  for (i = 0; i < q; i++) printf("%lld\n", ans[i]);
  return 0;
}
