12 12
5 1
5 11
1 11
8 11
8 9
5 12
6 9
7 11
9 3
9 10
4 12
10 2
78
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
5 5
5 6
5 7
5 8
5 9
5 10
5 11
5 12
6 6
6 7
6 8
6 9
6 10
6 11
6 12
7 7
7 8
7 9
7 10
7 11
7 12
8 8
8 9
8 10
8 11
8 12
9 9
9 10
9 11
9 12
10 10
10 11
10 12
11 11
11 12
12 12

1
3
6
10
15
21
28
36
45
55
65
76
1
3
6
10
15
21
28
36
45
55
66
1
3
6
10
15
21
28
36
45
55
1
3
6
10
15
21
28
36
45
1
3
6
10
15
21
28
36
1
3
6
10
15
21
28
1
3
6
10
15
21
1
3
6
10
15
1
3
6
10
1
3
6
1
3
1

#include <bits/stdc++.h>
using namespace std;
ofstream out("output.txt");
struct cyclevertexes {
  int min_num;
  int max_num;
  cyclevertexes() : min_num(0), max_num(0) {}
  cyclevertexes(int a, int b) : min_num(a), max_num(b) {}
  bool operator<(const cyclevertexes &c) const {
    if (min_num == c.min_num) return max_num < c.max_num;
    return min_num < c.min_num;
  }
};
vector<vector<int>> graph;
vector<int> color;
vector<bool> was;
vector<cyclevertexes> cycle;
stack<int> rec;
cyclevertexes get_cycle(int v) {
  int min_num = 1e9 - 10, max_num = -10;
  while (!rec.empty() && color[rec.top()] == 1) {
    int t = rec.top();
    rec.pop();
    min_num = min(min_num, t);
    max_num = max(max_num, t);
  }
  return cyclevertexes(min_num, max_num);
}
void dfs(int v, int p = -1) {
  rec.push(v);
  if (color[v] >= 2) {
    return;
  }
  if (color[v] == 1) {
    cycle.push_back(get_cycle(v));
    return;
  }
  color[v] = 1;
  for (int u : graph[v]) {
    if (u != p) dfs(u, v);
  }
  color[v] = 2;
  if (!rec.empty() && rec.top() == v) rec.pop();
}
long long binsearch(vector<long long> &L, long long l) {
  long long left = 0, right = (long long)L.size();
  while (right - left > 1) {
    long long middle = (left + right) / 2;
    if (L[middle] > l)
      right = middle;
    else
      left = middle;
  }
  return left;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  graph.resize(n);
  for (int i = 0; i < m; ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    graph[--from].push_back(--to);
    graph[to].push_back(from);
  }
  color.resize(n, 0);
  was.resize(n, false);
  for (int i = 0; i < n; ++i) dfs(i);
  vector<long long> fromposnum(n, 1e7);
  for (int i = 0; i < (int)cycle.size(); ++i) fromposnum[cycle[i].max_num] = i;
  vector<long long> L(n);
  int pos = 0, r = 0;
  while (r < n) {
    if (fromposnum[r] == 1e7) {
      L[r] = pos;
      ++r;
      continue;
    }
    pos = max(pos, cycle[fromposnum[r]].min_num + 1);
    L[r] = pos;
    ++r;
  }
  vector<long long> Lsums(n);
  Lsums[0] = L[0];
  for (int i = 1; i < n; ++i) Lsums[i] = Lsums[i - 1] + L[i];
  int query;
  scanf("%d", &query);
  for (int i = 0; i < query; ++i) {
    long long left, right;
    scanf("%I64d%I64d", &left, &right);
    --left;
    --right;
    long long M = binsearch(L, left);
    long long ans = (1LL - left) * (M - left + 1LL) +
                    (long long)(left + M) * (M - left + 1LL) / 2;
    ans += (M + 1LL + right) * (right - M) / 2 - (Lsums[right] - Lsums[M]) +
           (right - M);
    printf("%I64d\n", ans);
  }
  return 0;
}
