#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 10;
struct Tgraph {
  static const int maxn = 3e5 + 10, maxm = 6e5 + 10;
  struct Tedge {
    int son, ok;
    Tedge *pre, *bro;
    void add(int s_, Tedge *pre_) {
      son = s_;
      pre = pre_;
    }
  } edge[maxm], *now[maxn];
  int tot;
  void add(int a, int b) {
    edge[++tot].add(b, now[a]);
    now[a] = edge + tot;
    edge[tot].ok = 0;
  }
  void make(int a, int b) {
    add(a, b);
    add(b, a);
    edge[tot].bro = edge + tot - 1;
    edge[tot - 1].bro = edge + tot;
  }
  void clear() {
    tot = 0;
    memset(now, 0, sizeof(now));
  }
} G1, G2;
int last, sign, top;
int belong[maxn], low[maxn], dfn[maxn];
int sysx[maxn], stk[maxn];
Tgraph::Tedge *sysp[maxn];
int n, m, nxt[maxn];
void push(int x) {
  belong[x] = 0;
  dfn[x] = low[x] = ++sign;
  stk[++top] = x;
  sysx[++last] = x;
  sysp[x] = G1.now[x];
}
int num, tot;
struct Tlimit {
  int l, r;
} b[maxn];
bool cmp(Tlimit a, Tlimit b) { return a.l < b.l; }
struct Tquery {
  int l, r, id;
  long long ans;
} qr[maxn];
bool cmpl(Tquery a, Tquery b) { return a.l < b.l; }
bool cmpi(Tquery a, Tquery b) { return a.id < b.id; }
void Tarjan(int x) {
  for (sign = last = top = 0, push(x); last;) {
    for (x = sysx[last]; sysp[x]; sysp[x] = sysp[x]->pre) {
      if (sysp[x]->bro->ok) continue;
      sysp[x]->ok = 1;
      if (!dfn[sysp[x]->son]) {
        push(sysp[x]->son);
        break;
      } else if (!belong[sysp[x]->son])
        low[x] = min(low[x], dfn[sysp[x]->son]);
    }
    if (sysp[x]) continue;
    if (low[x] == dfn[x]) {
      num++;
      int minn = n + 1, maxx = 0, asd = 0;
      for (int t = -1; t != x; --top) {
        t = stk[top], belong[t] = num;
        asd++;
        minn = min(minn, t);
        maxx = max(maxx, t);
      }
      if (asd != 1) {
        tot++;
        b[tot].l = minn, b[tot].r = maxx;
      }
    }
    last--;
    int y = sysx[last];
    if (!last) break;
    low[y] = min(low[y], low[x]);
    sysp[y] = sysp[y]->pre;
  }
}
struct Tseg {
  long long p[maxn * 2], cov[maxn * 2];
  void modify(int root, int l, int r, int x, int y) {
    if (x == l && r == y) {
      cov[root]++;
      return;
    }
    p[root] += y - x + 1;
    int mid = (l + r) / 2;
    if (y <= mid)
      modify(root * 2, l, mid, x, y);
    else if (mid < x)
      modify(root * 2 + 1, mid + 1, r, x, y);
    else {
      modify(root * 2, l, mid, x, mid);
      modify(root * 2 + 1, mid + 1, r, mid + 1, y);
    }
  }
  long long query(int root, int l, int r, int x, int y) {
    long long ans = cov[root] * (y - x + 1);
    if (l == x && r == y) return ans + p[root];
    int mid = (l + r) / 2;
    if (y <= mid)
      ans += query(root * 2, l, mid, x, y);
    else if (mid < x)
      ans += query(root * 2 + 1, mid + 1, r, x, y);
    else {
      ans += query(root * 2, l, mid, x, mid);
      ans += query(root * 2 + 1, mid + 1, r, mid + 1, y);
    }
    return ans;
  }
} seg;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G1.make(x, y);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) Tarjan(i);
  sort(b + 1, b + tot + 1, cmp);
  for (int i = 1; i <= n; i++) nxt[i] = n;
  nxt[n + 1] = n;
  for (int i = tot; i; i--) {
    nxt[b[i].l] = min(nxt[b[i].l], b[i].r - 1);
  }
  for (int i = n; i; i--) {
    nxt[i] = min(nxt[i], nxt[i + 1]);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &qr[i].l, &qr[i].r);
    qr[i].id = i, qr[i].ans = 0;
  }
  sort(qr + 1, qr + q + 1, cmpl);
  int now = n;
  for (int i = q; i; i--) {
    while (now >= qr[i].l && now) seg.modify(1, 1, n, now, nxt[now]), now--;
    qr[i].ans = seg.query(1, 1, n, qr[i].l, qr[i].r);
  }
  sort(qr + 1, qr + q + 1, cmpi);
  for (int i = 1; i <= q; i++) printf("%I64d\n", qr[i].ans);
  return 0;
}
