#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000001;
const long long LINF = 1000000000000000001LL;
pair<int, int> op_modify(pair<int, int> a, int b) {
  return pair<int, int>(a.first + a.second * b, a.second);
}
int op_buf(int a, int b) { return a + b; }
pair<int, int> op_query(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
const pair<int, int> NODE_INIT = pair<int, int>(0, 1);
const int MODIFY_NEUTRAL = 0;
struct LinkCutTree {
  struct node {
    node *par, *child[2];
    bool rev;
    int buf;
    pair<int, int> val, res;
  };
  vector<node> _node;
  void init(int n) {
    _node.assign(
        n, node{NULL, {NULL, NULL}, 0, MODIFY_NEUTRAL, NODE_INIT, NODE_INIT});
  }
  void link(int _a, int _b) {
    node *a = &_node[_a], *b = &_node[_b];
    _change_root(a);
    a->par = b;
  }
  void cut(int _a, int _b) {
    node *a = &_node[_a], *b = &_node[_b];
    _change_root(a);
    _access(b);
    _splay(b);
    _set_child(b, NULL, 0);
    a->par = NULL;
  }
  void modify(int _a, int _b, int v) {
    node *a = &_node[_a], *b = &_node[_b];
    _change_root(a);
    _access(b);
    _splay(b);
    b->buf = op_buf(b->buf, v);
  }
  pair<int, int> query(int _a, int _b) {
    node *a = &_node[_a], *b = &_node[_b];
    _change_root(a);
    _access(b);
    _splay(b);
    return b->res;
  }
  int find_root(int _x) {
    node *x = &_node[_x];
    _access(x);
    _splay(x);
    while (x->child[0]) x = x->child[0];
    _splay(x);
    return x - _node.data();
  }
  void _change_root(node *x) {
    _access(x);
    _splay(x);
    x->rev ^= 1;
  }
  void _access(node *x) {
    for (node *cur = NULL; x; x = x->par) {
      _splay(x);
      _set_child(x, cur, 1);
      cur = x;
    }
  }
  bool _is_root(node *x) {
    return !x->par || (x->par->child[1] != x && x->par->child[0] != x);
  }
  void _push(node *x) {
    if (x->child[0]) {
      x->child[0]->rev ^= x->rev;
      x->child[0]->buf = op_buf(x->child[0]->buf, x->buf);
    }
    if (x->child[1]) {
      x->child[1]->rev ^= x->rev;
      x->child[1]->buf = op_buf(x->child[1]->buf, x->buf);
    }
    if (x->rev) {
      swap(x->child[0], x->child[1]);
      x->rev = 0;
    }
    x->val = op_modify(x->val, x->buf);
    x->buf = MODIFY_NEUTRAL;
  }
  void _update(node *x) {
    x->res = x->val;
    if (x->child[0]) {
      x->res = op_query(x->res, op_modify(x->child[0]->res, x->child[0]->buf));
    }
    if (x->child[1]) {
      x->res = op_query(x->res, op_modify(x->child[1]->res, x->child[1]->buf));
    }
  }
  void _set_child(node *x, node *c, int t) {
    _push(x);
    x->child[t] = c;
    if (c) c->par = x;
    _update(x);
  }
  void _rotate(node *x) {
    node *p = x->par;
    x->par = p->par;
    if (!_is_root(p)) _set_child(p->par, x, !(p == p->par->child[0]));
    int f = (x == p->child[0]);
    _set_child(p, x->child[f], !f);
    _set_child(x, p, f);
  }
  void _splay(node *x) {
    static vector<node *> r;
    node *p;
    for (p = x; !_is_root(p); p = p->par) r.push_back(p);
    for (r.push_back(p); !r.empty(); r.pop_back()) _push(r.back());
    for (; !_is_root(x); _rotate(x))
      if (!_is_root(x->par) &&
          (x == x->par->child[0]) == (x->par == x->par->par->child[0])) {
        _rotate(x->par);
      }
  }
};
struct ITree {
  vector<long long> T;
  int p = 1;
  ITree(int n) {
    while (p < n) p *= 2;
    T.resize(2 * p - 1, 0);
  }
  int par(int x) { return (x - 1) / 2; }
  void add(int l, long long v) {
    l += p - 1;
    T[l] += v;
    while (l > 0) {
      l = par(l);
      T[l] += v;
    }
  }
  long long query(int l, int r) {
    l += p - 1;
    r += p - 1;
    long long ans = T[l];
    if (l < r) ans += T[r];
    while (par(l) != par(r)) {
      if (l % 2 == 1) ans += T[l + 1];
      if (r % 2 == 0) ans += T[r - 1];
      l = par(l);
      r = par(r);
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > g(n);
  for (int _ = (1); _ <= (m); ++_) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  LinkCutTree tree;
  tree.init(n);
  vector<int> pos(n);
  vector<int> aux(n);
  for (int i = (n - 1); i >= (0); --i) {
    pos[i] = (i == n - 1 ? n - 1 : pos[i + 1]);
    while (pos[i] > i) {
      bool bad = false;
      for (int j : g[i])
        if (j > i && j <= pos[i]) {
          int r = tree.find_root(j);
          aux[r]++;
          if (aux[r] > 1) {
            bad = true;
          }
        }
      for (int j : g[i])
        if (j > i && j <= pos[i]) {
          aux[tree.find_root(j)]--;
        }
      if (bad) {
        for (int j : g[pos[i]])
          if (j >= i && j < pos[i]) {
            tree.cut(j, pos[i]);
          }
        pos[i]--;
      } else {
        break;
      }
    }
    for (int j : g[i])
      if (j > i && j <= pos[i]) {
        tree.link(j, i);
      }
  }
  ITree itree(n);
  for (int i = (0); i <= (n - 1); ++i) {
    itree.add(i, pos[i]);
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    int ind = lower_bound(pos.begin(), pos.end(), r) - pos.begin();
    ind = max(ind, l);
    int len = max(0, r - ind + 1);
    long long ans = (long long)len * (len + 1) / 2;
    if (ind > l) {
      int p = min(ind - 1, r);
      ans += itree.query(l, p);
      ans -= (long long)(p - l + 1) * (p + l - 2) / 2;
    }
    cout << ans << '\n';
  }
  return 0;
}
