#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
class UnionFind {
 private:
  int n;
  vector<int> parent, r;
  int _find(int x) {
    if (parent[x] == x)
      return x;
    else
      return parent[x] = _find(parent[x]);
  }
  void _unite(int x, int y) {
    x = _find(x);
    y = _find(y);
    if (x == y) return;
    if (r[x] < r[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (r[x] == r[y]) r[x]++;
    }
  }

 public:
  int find(int x) { return _find(x); }
  void unite(int x, int y) { return _unite(x, y); }
  int operator[](int i) { return find(i); }
  UnionFind() : n(0) {}
  explicit UnionFind(size_t _n) : n(_n) {
    parent = vector<int>(n);
    r = vector<int>(n, 0);
    for (int i = 0; i < n; i++) {
      parent[i] = i;
    }
  }
};
class Task {
 public:
  int N, M, Q;
  vector<int> used, current, left, right;
  vector<vector<int>> G;
  vector<queue<int>> que;
  UnionFind ds;
  void dfs(int s, int p) {
    used[s] = 1;
    current.push_back(s);
    for (auto u : G[s]) {
      if (u == p) continue;
      if (used[u] == 1) {
        int idx = (int)(current).size() - 1;
        while (idx and current[idx] != u) {
          ds.unite(current[idx], current[idx - 1]);
          --idx;
        }
      } else if (not used[u])
        dfs(u, s);
    }
    used[s] = 2;
    current.pop_back();
  }
  void solve() {
    cin >> N >> M;
    used = vector<int>(N, 0);
    left = vector<int>(N, N);
    right = vector<int>(N, -1);
    G = vector<vector<int>>(N, vector<int>());
    que = vector<queue<int>>(N, queue<int>());
    ds = UnionFind(N);
    for (int(i) = (0); (i) < (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) < (N); ++(i))
      if (not used[i]) dfs(i, -1);
    for (int(i) = (0); (i) < (N); ++(i)) {
      int p = ds.find(i);
      chmin(left[p], i);
      chmax(right[p], i);
    }
    for (int(i) = (0); (i) < (N); ++(i)) {
      int p = ds.find(i);
      left[i] = left[p];
      right[i] = right[p];
    }
    int j = 0, cnt = 0;
    vector<long long> len(N, 0), sum(N + 1, 0);
    for (int(i) = (0); (i) < (N); ++(i)) {
      while (j < N and (left[j] < i or j < right[j] or left[j] == right[j]))
        ++j;
      len[i] = j - 1;
      sum[i + 1] = sum[i] + len[i] - i + 1;
    }
    cin >> Q;
    for (int(i) = (0); (i) < (Q); ++(i)) {
      long long l, r;
      cin >> l >> r;
      l--, r--;
      long long idx =
          distance(len.begin(), upper_bound((len).begin(), (len).end(), r));
      chmax(idx, l);
      chmin(idx, r);
      long long ans = sum[idx] - sum[l] + (r - idx + 1) * (r - idx + 2) / 2;
      cout << ans << '\n';
    }
  }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  Task solver = Task();
  solver.solve();
  return 0;
}
