#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
vector<int> g[maxn];
int n, m, vis[maxn], dfn[maxn], low[maxn], stk[maxn], top, cnt, mx[maxn];
long long sum[maxn];
void Get_Cycle(int p) {
  int l = INF, r = -INF;
  while (true) {
    int u = stk[top--];
    l = min(l, u);
    r = max(r, u);
    if (u == p) break;
  }
  mx[l] = r;
}
void dfs(int o, int p) {
  low[o] = dfn[o] = ++cnt;
  vis[o] = 1;
  stk[++top] = o;
  for (int i = 0; i < g[o].size(); i++) {
    int v = g[o][i];
    if (v == p) continue;
    if (!vis[v]) dfs(v, o);
    low[o] = min(low[o], min(dfn[v], low[v]));
  }
  if (low[o] == dfn[o]) Get_Cycle(o);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  int temp = n;
  for (int i = n; i >= 1; i--) {
    int u = mx[i];
    if (u && u != i)
      temp = mx[i] = min(u - 1, temp);
    else
      mx[i] = temp;
  }
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + mx[i] - i + 1;
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int a = l, b = r;
    while (r > l) {
      int mid = (r + l) >> 1;
      if (mx[mid] >= b)
        r = mid;
      else
        l = mid + 1;
    }
    long long s = b - l + 1;
    long long ans = s * (s + 1) / 2 + sum[l - 1] - sum[a - 1];
    printf("%lld\n", ans);
  }
  return 0;
}
