#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
struct Edg {
  int lst, ed;
} e[N << 1];
struct SegJieDian {
  long long val, tag;
  SegJieDian() { val = tag = 0; }
} S[N << 2];
int ne = 0, nte[N];
int tot = 0, top = 0, dfn[N], low[N], sta[N];
int d[N];
long long ans[N];
vector<pair<int, int> > qr[N];
int rd() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x;
}
void NewEdg(int u, int v) {
  ne++;
  e[ne].lst = nte[u];
  e[ne].ed = v;
  nte[u] = ne;
}
void dfs(int x) {
  dfn[x] = low[x] = ++tot;
  sta[++top] = x;
  for (int i = nte[x]; i; i = e[i].lst)
    if (!dfn[e[i].ed]) {
      dfs(e[i].ed);
      low[x] = min(low[x], low[e[i].ed]);
      if (low[e[i].ed] >= dfn[x]) {
        int L = x, R = x, siz = 1;
        while (sta[top + 1] != e[i].ed) {
          R = max(R, sta[top]);
          L = min(L, sta[top]);
          top--, siz++;
        }
        if (siz > 2) d[R] = max(d[R], L);
      }
    } else
      low[x] = min(low[x], dfn[e[i].ed]);
}
void AddNode(int p, int l, int r, long long w) {
  S[p].val += (r - l + 1) * w;
  S[p].tag += w;
}
void PushDown(int p, int l, int r) {
  if (!S[p].tag) return;
  int mid = (l + r) >> 1;
  AddNode(p << 1, l, mid, S[p].tag);
  AddNode(p << 1 | 1, mid + 1, r, S[p].tag);
  S[p].tag = 0;
}
void PushUp(int p) { S[p].val = S[p << 1].val + S[p << 1 | 1].val; }
void AddLR(int p, int l, int r, int x, int y, long long w) {
  if (l == x && r == y) {
    AddNode(p, l, r, w);
    return;
  }
  PushDown(p, l, r);
  int mid = (l + r) >> 1;
  if (y <= mid)
    AddLR(p << 1, l, mid, x, y, w);
  else if (x > mid)
    AddLR(p << 1 | 1, mid + 1, r, x, y, w);
  else {
    AddLR(p << 1, l, mid, x, mid, w);
    AddLR(p << 1 | 1, mid + 1, r, mid + 1, y, w);
  }
  PushUp(p);
}
long long AskLR(int p, int l, int r, int x, int y) {
  if (l == x && r == y) return S[p].val;
  PushDown(p, l, r);
  int mid = (l + r) >> 1;
  if (y <= mid) return AskLR(p << 1, l, mid, x, y);
  if (x > mid) return AskLR(p << 1 | 1, mid + 1, r, x, y);
  return AskLR(p << 1, l, mid, x, mid) +
         AskLR(p << 1 | 1, mid + 1, r, mid + 1, y);
}
int main() {
  int n = rd(), m = rd();
  for (int i = 1; i <= m; i++) {
    int x = rd(), y = rd();
    NewEdg(x, y), NewEdg(y, x);
  }
  int q = rd();
  for (int i = 1; i <= q; i++) {
    int l = rd(), r = rd();
    qr[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  int k = 0;
  for (int i = 1; i <= n; i++) {
    k = min(i - d[i], k + 1);
    AddLR(1, 1, n, i - k + 1, i, 1);
    int siz = qr[i].size();
    for (int j = 0; j < siz; j++)
      ans[qr[i][j].second] = AskLR(1, 1, n, qr[i][j].first, i);
  }
  for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
  return 0;
}
