#include <bits/stdc++.h>
class Solver {
  int n, m, q;
  std::vector<std::vector<int>> g;
  std::vector<int> tin;
  std::vector<int> tout;
  std::vector<int> visited;
  std::vector<int> parent;
  std::vector<std::vector<int>> cycles;
  std::vector<int> mx;
  std::vector<int64_t> prefix_mx;
  std::vector<int64_t> prefix_i;

 public:
  Solver() = default;
  void read() {
    std::cin >> n >> m;
    g.resize(n + 1);
    for (int i = 0; i < m; ++i) {
      int a, b;
      std::cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    tin.resize(n + 1, 0);
    tout.resize(n + 1, 0);
    visited.resize(n + 1, 0);
    parent.resize(n + 1, 0);
    mx.resize(n + 1, 0);
    prefix_mx.resize(n + 1, 0);
    prefix_i.resize(n + 1, 0);
  }
  void solve() {
    for (int i = 1; i <= n; ++i) {
      if (visited[i] == 0) {
        dfs(i, -1);
      }
    }
    int tmp_mx = n;
    for (int v = n; v >= 1; --v) {
      if (mx[v] != 0) {
        tmp_mx = std::min(tmp_mx, mx[v] - 1);
      }
      mx[v] = tmp_mx;
    }
    for (int i = 1; i <= n; ++i) {
      prefix_mx[i] += prefix_mx[i - 1] + mx[i] - i + 1;
      prefix_i[i] += prefix_i[i - 1] + i;
    }
    int q;
    std::cin >> q;
    for (int qi = 0; qi < q; ++qi) {
      int l, r;
      std::cin >> l >> r;
      auto treshold =
          std::upper_bound(mx.begin() + 1, mx.end(), r) - mx.begin() - 1;
      int64_t answer = 0;
      if (!(l <= treshold && treshold <= r)) {
        answer = prefix_i[r - l + 1];
      } else {
        auto mx_answer = prefix_mx[treshold] - prefix_mx[l - 1];
        auto i_answer = prefix_i[r - treshold];
        answer = mx_answer + i_answer;
      }
      std::cout << answer << "\n";
    }
  }
  void write() {}
  void dfs(int v, int father) {
    parent[v] = father;
    visited[v] = 1;
    for (auto child : g[v]) {
      if (child != father) {
        if (visited[child] == 2) {
          continue;
        }
        if (visited[child]) {
          int ci = cycles.size();
          cycles.push_back(std::vector<int>());
          cycles[ci].push_back(v);
          int min = v;
          int max = v;
          visited[v] = 2;
          int u = v;
          while (u != child) {
            u = parent[u];
            cycles[ci].push_back(u);
            visited[u] = 2;
            min = std::min(min, u);
            max = std::max(max, u);
          }
          mx[min] = max;
        } else {
          dfs(child, v);
        }
      }
    }
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  Solver solver;
  solver.read();
  solver.solve();
  solver.write();
  return 0;
}
