#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, q, low[N], vis[N];
long long pre[N];
vector<int> es[N];
stack<int> stk;
void dfs(int u, int par) {
  stk.push(u);
  vis[u] = 1;
  for (auto v : es[u])
    if (v != par) {
      if (!vis[v])
        dfs(v, u);
      else if (vis[v] == 1) {
        int mn = v, mx = v;
        while (!stk.empty()) {
          int cur = stk.top();
          stk.pop();
          mn = min(mn, cur);
          mx = max(mx, cur);
          if (cur == v) break;
        }
        low[mx] = mn;
      }
    }
  if (!stk.empty() && stk.top() == u) stk.pop();
  vis[u] = 2;
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int _ = 0; _ < m; _++) {
    int a, b;
    scanf("%d%d", &a, &b);
    es[a].push_back(b);
    es[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  for (int i = 1; i <= n; i++) {
    low[i] = max(low[i], low[i - 1]);
    pre[i] = pre[i - 1] + i - low[i];
  }
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int lo = l, hi = r;
    while (lo < hi) {
      int mid = (lo + hi + 1) / 2;
      if (low[mid] < l)
        lo = mid;
      else
        hi = mid - 1;
    }
    printf("%lld\n", pre[r] - pre[lo] + 1ll * (lo - l + 1) * (lo - l + 2) / 2);
  }
}
int main() {
  solve();
  return 0;
}
