#include <bits/stdc++.h>
struct lct {
  int pre[300100];
  void makeroot(int x) {
    for (int y = 0, fa = pre[x]; x; fa = pre[x = fa]) {
      pre[x] = y;
      y = x;
    }
  }
  bool connected(int a, int b) {
    makeroot(a);
    for (; a != b && b; b = pre[b])
      ;
    return a == b;
  }
  void link(int x, int y) {
    makeroot(x);
    pre[x] = y;
  }
  void cut(int x, int y) {
    makeroot(x);
    pre[y] = 0;
  }
};
lct tr;
int mtree[300100];
long long prefsum[300100];
int n;
std::vector<int> g[300100];
bool canadd(int l, int r) {
  std::vector<std::pair<int, int>> changes;
  for (int c : g[r]) {
    if (c >= l && c <= r) {
      if (tr.connected(c, r)) {
        for (auto p : changes) tr.cut(p.first, p.second);
        return false;
      } else {
        changes.emplace_back(c, r);
        tr.link(c, r);
      }
    }
  }
  return true;
}
int remove(int l, int r) {
  for (int c : g[l])
    if (c >= l && c <= r) tr.cut(l, c);
  return l;
}
void gettrees(void) {
  int l = 1;
  int r = 2;
  while (l <= n && r <= n) {
    if (canadd(l, r))
      r++;
    else
      mtree[remove(l++, r)] = r;
  }
  for (int i = 1; i <= n; i++)
    if (mtree[i] == 0) mtree[i] = n + 1;
}
void initprefsum(void) {
  for (int i = 1; i <= n; i++) prefsum[i] = mtree[i] - i;
  for (int i = 2; i <= n; i++) prefsum[i] += prefsum[i - 1];
}
long long query(int l0, int r0) {
  int l = l0, r = r0;
  long long ans = 0;
  while (l < r) {
    int mid = (l + r) / 2;
    if (mtree[mid] > r0)
      r = mid;
    else
      l = mid + 1;
  }
  long long len = r0 - l + 1;
  ans += len * (len + 1) / 2;
  ans += prefsum[l - 1] - prefsum[l0 - 1];
  return ans;
}
int main(void) {
  int m, q;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int src, dst;
    scanf("%d%d", &src, &dst);
    g[src].push_back(dst);
    g[dst].push_back(src);
  }
  gettrees();
  initprefsum();
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%lld\n", query(l, r));
  }
  return 0;
}
