#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
long long sum[N + 10], ans[N + 10];
int vis[N + 10], par[N + 10], cyc[N + 10];
vector<int> g[N + 10], ele;
vector<pair<int, int> > Q[N + 10];
long long cou(long long a) { return (a * (a + 1)) / 2; }
void dfs(int v, int p) {
  vis[v] = 1;
  for (auto it : g[v]) {
    if (it == p) {
      continue;
    }
    if (!vis[it]) {
      par[it] = v;
      dfs(it, v);
    } else if (vis[it] == 1) {
      int mx = v, mn = v, cur = v;
      while (cur != it) {
        mx = max(mx, par[cur]);
        mn = min(mn, par[cur]);
        cur = par[cur];
      }
      cyc[mx] = mn;
    }
  }
  vis[v] = 2;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; 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 mx = 0;
  for (int i = 1; i <= n; i++) {
    if (cyc[i] > mx) {
      for (int j = mx + 1; j <= cyc[i]; j++) {
        sum[j] = n - i + 1;
      }
      ele.push_back(i);
      mx = cyc[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    sum[i] += sum[i - 1];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    long long total = cou(r - l + 1);
    auto idx = lower_bound(ele.begin(), ele.end(), r + 1) - ele.begin();
    if (idx == 0) {
      printf("%lld\n", total);
      continue;
    }
    idx--;
    int lst = ele[idx];
    if (cyc[lst] < l) {
      printf("%lld\n", total);
      continue;
    }
    total -= (sum[cyc[lst]] - sum[l - 1]);
    total += 1ll * (n - r) * (cyc[lst] - l + 1);
    printf("%lld\n", total);
  }
}
