#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void read(long long &x) {
  char ch;
  while (blank(ch = nc()))
    ;
  if (IOerror) return;
  for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0')
    ;
}
inline void read(int &x) {
  char ch;
  while (blank(ch = nc()))
    ;
  if (IOerror) return;
  for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0')
    ;
}
inline void read(char *s) {
  char ch;
  while (blank(ch = nc()))
    ;
  if (IOerror) return;
  int i = 0;
  for (; !blank(ch); s[i++] = ch, ch = nc())
    ;
  s[i] = '\0';
}
};  // namespace fastIO
using namespace fastIO;
vector<int> g[maxn];
int vis[maxn];
stack<int> S;
int p[maxn];
long long sum[maxn];
void dfs(int u, int fa) {
  S.push(u);
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != fa) {
      if (vis[v] == 0)
        dfs(v, u);
      else if (vis[v] == 1) {
        int Max = u, Min = u;
        while (!S.empty()) {
          int w = S.top();
          S.pop();
          Max = max(Max, w);
          Min = min(Min, w);
          if (w == v) break;
        }
        p[Min] = Max;
      }
    }
  }
  if (!S.empty() && S.top() == u) S.pop();
  vis[u] = 2;
}
int main() {
  int n, m, q;
  read(n);
  read(m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    read(a);
    read(b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n + 1; i++) p[i] = n + 1;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) dfs(i, -1);
  }
  sum[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    p[i] = min(p[i], p[i + 1]);
    sum[i] = p[i] - i + sum[i + 1];
  }
  read(q);
  while (q--) {
    int l, r;
    read(l);
    read(r);
    int L = l, R = r, P = l;
    while (L <= R) {
      int m = L + R >> 1;
      if (p[m] <= r)
        L = m + 1;
      else {
        P = m;
        R = m - 1;
      }
    }
    printf("%I64d\n", sum[l] - sum[P] + 1LL * (r - P + 2) * (r - P + 1) / 2);
  }
  return 0;
}
