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;
const int N = 510031;
int n, m;
vector<int> g[N];
int cut[N], R[N];
long long SR[N];
int tests;
vector<int> qu_list[N];
vector<int> updates[N];
pair<long long, long long> t[N * 4];
int test_l[N], test_r[N];
long long ans[N];
long long SumProg[N];
pair<long long, long long> combine(pair<long long, long long> p1,
                                   pair<long long, long long> p2) {
  p1.first += p2.first;
  p1.second += p2.second;
  return p1;
}
void add(int v, int tl, int tr, int ps, int val) {
  if (tl == tr) {
    t[v].first += 1;
    t[v].second += val;
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    add(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    add(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = combine(t[v * 2], t[v * 2 + 1]);
}
pair<long long, long long> get(int v, int tl, int tr, int l, int r) {
  if (l > r) return make_pair(0, 0);
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  return combine(
      get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
      get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r));
}
int used[N];
vector<int> cycle;
int par[N];
void restore_cycle(int v, int start) {
  cycle.clear();
  while (v != start) {
    cycle.push_back(v);
    v = par[v];
  }
  cycle.push_back(start);
  sort(cycle.begin(), cycle.end());
  R[cycle[0]] = cycle.back() - 1;
}
void dfs(int v, int p = -1) {
  used[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p || used[to] == 2) continue;
    if (used[to]) {
      restore_cycle(v, to);
      continue;
    }
    par[to] = v;
    dfs(to, v);
  }
  used[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    SumProg[i] = SumProg[i - 1] + i - 1;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    R[i] = n;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    dfs(i);
  }
  for (int i = n - 1; i >= 1; i--) {
    R[i] = min(R[i], R[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    updates[R[i]].push_back(i);
    SR[i] = SR[i - 1] + R[i];
  }
  cin >> tests;
  for (int test = 1; test <= tests; test++) {
    cin >> test_l[test] >> test_r[test];
    qu_list[test_r[test]].push_back(test);
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < updates[i].size(); j++) {
      int ps = updates[i][j];
      add(1, 1, n, ps, i);
    }
    for (int j = 0; j < qu_list[i].size(); j++) {
      int test = qu_list[i][j];
      long long res = SR[test_r[test]] - SR[test_l[test] - 1];
      res -= SumProg[test_r[test]] - SumProg[test_l[test] - 1];
      pair<long long, long long> p = get(1, 1, n, test_l[test], test_r[test]);
      res -= p.second;
      res += p.first * test_r[test];
      ans[test] = res;
    }
  }
  for (int i = 1; i <= tests; i++) {
    cout << ans[i] << "\n";
  }
  cin.get();
  cin.get();
  return 0;
}
