#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 300007;
const int MAXS = MAXN * 4;
const int MAX = 524288;
class lctT {
 public:
  void link(int u, int v) {
    croot(u);
    access(v);
    fa[u] = v;
    access(u);
  }
  void cut(int u, int v) {
    croot(u);
    access(v);
    if (ch[v][0] == u) ch[v][0] = fa[u] = 0;
  }
  bool query(int u, int v) { return iscon(u, v); }

 private:
  void rot(int now) {
    int nf = fa[now], np = fa[nf], d = (ch[nf][1] == now);
    fa[now] = np;
    if (!isroot(nf)) ch[np][ch[np][1] == nf] = now;
    fa[ch[now][d ^ 1]] = nf, ch[nf][d] = ch[now][d ^ 1];
    fa[nf] = now, ch[now][d ^ 1] = nf;
  }
  void splay(int now) {
    rev_push(now);
    int nf, np;
    while (!isroot(now)) {
      nf = fa[now], np = fa[nf];
      if (!isroot(nf))
        rot(((ch[nf][0] == now) == (ch[np][0] == nf)) ? nf : now);
      rot(now);
    }
  }
  void access(int now) {
    int v = 0, tn = now;
    while (now) {
      splay(now);
      ch[now][1] = v;
      v = now, now = fa[now];
    }
    splay(tn);
  }
  void croot(int now) {
    access(now);
    tag[now] ^= 1;
  }
  int getroot(int now) {
    while (ch[now][0]) now = ch[now][0];
    splay(now);
    return now;
  }
  bool iscon(int u, int v) {
    croot(u);
    access(v);
    return getroot(v) == u;
  }
  bool isroot(int now) {
    return (!(fa[now] && (ch[fa[now]][0] == now || ch[fa[now]][1] == now)));
  }
  void push_down(int now) {
    if (tag[now]) {
      tag[ch[now][0]] ^= 1, tag[ch[now][1]] ^= 1;
      swap(ch[now][0], ch[now][1]);
      tag[now] = 0;
    }
  }
  void rev_push(int now) {
    if (!isroot(now)) rev_push(fa[now]);
    push_down(now);
  }
  int fa[MAXN], ch[MAXN][2];
  bool tag[MAXN];
} lct;
class stT {
 public:
  void upd(int l, int r, int x, int now = 1, int ll = 1, int rr = MAX) {
    if (ll >= l && rr <= r)
      tag[now] += x, data[now] += static_cast<long long>(x) * (rr - ll + 1);
    else if (rr < l || ll > r)
      return;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now, rr - ll + 1);
      upd(l, r, x, now << 1, ll, mid);
      upd(l, r, x, now << 1 | 1, mid + 1, rr);
      data[now] = data[now << 1] + data[now << 1 | 1];
    }
  }
  long long query(int l, int r, int now = 1, int ll = 1, int rr = MAX) {
    if (ll >= l && rr <= r)
      return data[now];
    else if (rr < l || ll > r)
      return 0;
    else {
      int mid = (ll + rr) >> 1;
      downtag(now, rr - ll + 1);
      return query(l, r, now << 1, ll, mid) +
             query(l, r, now << 1 | 1, mid + 1, rr);
    }
  }

 private:
  void downtag(int now, int ns) {
    if (tag[now]) {
      tag[now << 1] += tag[now], tag[now << 1 | 1] += tag[now];
      data[now << 1] += static_cast<long long>(tag[now]) * (ns >> 1),
          data[now << 1 | 1] += static_cast<long long>(tag[now]) * (ns >> 1);
      tag[now] = 0;
    }
  }
  int tag[MAXS];
  long long data[MAXS];
} st;
struct eT {
  void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
  int u, v, last;
} edge[MAXN * 2];
struct qT {
  int id, l, r;
  long long ans;
} que[MAXN];
int n, m, q;
int eu[MAXN], ev[MAXN];
int ke, la[MAXN];
int vl[MAXN];
void init();
void input();
void work();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &eu[i], &ev[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i)
    scanf("%d%d", &que[i].l, &que[i].r), que[i].id = i;
}
void work() {
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 1; i <= m; ++i) {
    edge[ke].setd(eu[i], ev[i], la[eu[i]]);
    la[eu[i]] = ke++;
    edge[ke].setd(ev[i], eu[i], la[ev[i]]);
    la[ev[i]] = ke++;
  }
  int nl = 1;
  for (int nr = 1; nr <= n; ++nr) {
    for (int i = la[nr]; ~i; i = edge[i].last) {
      if (edge[i].v >= nl && edge[i].v <= nr) {
        while (lct.query(edge[i].u, edge[i].v)) {
          for (int j = la[nl]; ~j; j = edge[j].last) {
            if (edge[j].v >= nl && edge[j].v <= nr) {
              lct.cut(edge[j].u, edge[j].v);
            }
          }
          ++nl;
        }
        lct.link(edge[i].u, edge[i].v);
      }
    }
    vl[nr] = nl;
  }
  sort(que + 1, que + 1 + q,
       [](const qT &x, const qT &y) { return x.r < y.r; });
  int iq = 1;
  for (int i = 1; i <= n; ++i) {
    st.upd(vl[i], i, 1);
    while (iq <= q && que[iq].r == i) {
      que[iq].ans = st.query(que[iq].l, que[iq].r);
      ++iq;
    }
  }
  sort(que + 1, que + 1 + q,
       [](const qT &x, const qT &y) { return x.id < y.id; });
  for (int i = 1; i <= q; ++i) printf("%I64d\n", que[i].ans);
}
