#include <bits/stdc++.h>
using namespace std;
vector<int> graph[300030];
long long to[300030], sum[300030];
int vis[300030], dep[300030], parent[300030], group[300030];
int cyc, cnt[300030], gcnt[300030];
void dfs(int node, int p, int d = 1) {
  if (vis[node]) return;
  vis[node] = 1;
  dep[node] = d;
  parent[node] = p;
  for (int to : graph[node]) {
    if (vis[to] && dep[to] < d && to != p) {
      ++cyc;
      for (int k = node; k > 0; k = parent[k]) {
        group[k] = cyc;
        gcnt[cyc]++;
        if (k == to) break;
      }
    }
    dfs(to, node, d + 1);
  }
}
void count(int x, int val) {
  if (group[x] > 0) cnt[group[x]] += val;
}
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);
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, -1);
  }
  int e = 1;
  count(e, 1);
  for (int i = 1; i <= n; i++) {
    to[i] = ((e) < (n) ? (e) : (n));
    while (++e <= n) {
      count(e, 1);
      if (group[e] > 0 && cnt[group[e]] == gcnt[group[e]]) {
        count(e, -1);
        --e;
        break;
      }
      to[i] = e;
    }
    sum[i] = sum[i - 1] + to[i];
    count(i, -1);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    long long l, r, pos = x - 1;
    l = x;
    r = y;
    while (l <= r) {
      long long m = (l + r) >> 1;
      if (to[m] <= y) {
        pos = m;
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
    long long l1 = pos - x + 1;
    long long l2 = y - pos;
    printf("%lld\n", sum[pos] - sum[x - 1] - l1 * (l1 - 1) / 2 - (x - 1) * l1 +
                         l2 * (l2 + 1) / 2);
  }
  return 0;
}
