#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
int n, m;
vector<vector<int>> adj;
vector<int> h, p;
void DFS(int v) {
  for (int i = 0; i < ((int)(adj[v]).size()); ++i) {
    int u = adj[v][i];
    if (h[u] == -1) {
      h[u] = h[v] + 1;
      p[u] = v;
      DFS(u);
    }
  }
}
pair<int, int> MinMax(int v1, int v2) {
  int min_num = min(v1, v2);
  int max_num = max(v1, v2);
  if (h[v1] > h[v2]) {
    swap(v1, v2);
  }
  while (h[v2] > h[v1]) {
    v2 = p[v2];
    min_num = min(min_num, v2);
    max_num = max(max_num, v2);
  }
  while (v1 != v2) {
    v1 = p[v1];
    v2 = p[v2];
    min_num = min(min_num, min(v1, v2));
    max_num = max(max_num, max(v1, v2));
  }
  return make_pair(min_num, max_num);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  adj.resize(n);
  for (int i = 0; i < m; ++i) {
    int v1, v2;
    cin >> v1 >> v2;
    --v1, --v2;
    adj[v1].push_back(v2);
    adj[v2].push_back(v1);
  }
  int q;
  cin >> q;
  vector<pair<int, int>> seg(q);
  for (int i = 0; i < q; ++i) {
    cin >> seg[i].first >> seg[i].second;
    --seg[i].first;
  }
  h.resize(n, -1);
  p.resize(n, -1);
  for (int i = 0; i < n; ++i) {
    if (h[i] == -1) {
      h[i] = 0;
      DFS(i);
    }
  }
  vector<int> min_cycle(n, n);
  for (int v = 0; v < n; ++v) {
    for (int i = 0; i < ((int)(adj[v]).size()); ++i) {
      int u = adj[v][i];
      if (v < u && p[v] != u && p[u] != v) {
        pair<int, int> min_max = MinMax(v, u);
        min_cycle[min_max.first] =
            min(min_cycle[min_max.first], min_max.second);
      }
    }
  }
  vector<int> right(n);
  right[n - 1] = min_cycle[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    right[i] = min(right[i + 1], min_cycle[i]);
  }
  vector<long long> sum_right(n + 1);
  vector<long long> sum_left(n + 1);
  sum_left[0] = sum_right[0] = 0;
  for (int i = 0; i < n; ++i) {
    sum_left[i + 1] = sum_left[i] + i;
    sum_right[i + 1] = sum_right[i] + right[i];
  }
  vector<long long> sum_len(n + 1);
  for (int i = 0; i <= n; ++i) {
    sum_len[i] = sum_right[i] - sum_left[i];
  }
  vector<long long> res(q);
  for (int i = 0; i < q; ++i) {
    int ind =
        lower_bound(right.begin(), right.end(), seg[i].second) - right.begin();
    ind = min(max(ind, seg[i].first), seg[i].second);
    res[i] = (sum_len[ind] - sum_len[seg[i].first]) +
             (seg[i].second - ind) * (long long)seg[i].second -
             (sum_left[seg[i].second] - sum_left[ind]);
  }
  for (int i = 0; i < q; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}
