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 maxn = 3e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
vector<int> ger[maxn];
bool vis[maxn];
int rang[maxn];
int dfs(int a, int par) {
  if (rang[a] != -1) {
    return -1;
  }
  if (vis[a]) {
    return a;
  }
  vis[a] = 1;
  int dor = -1;
  for (int i = 0; i < ger[a].size(); i++) {
    int v = ger[a][i];
    if (v != par) {
      int u = dfs(v, a);
      if (u != -1) {
        dor = u;
      }
    }
  }
  rang[a] = dor;
  if (dor == a) {
    return -1;
  }
  return dor;
}
void ffty(int n) {
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs(i, -1);
    }
  }
}
long long ans[maxn];
int f[maxn];
vector<int> vec[maxn];
int r[maxn];
int fir[maxn];
int las[maxn];
int s[maxn * 8];
long long sum[maxn * 8];
int hes(int s, int d, int t) { return s * t + (t - 1) * t * d / 2; }
void update(int L, int R, int node, int l, int r) {
  if (l <= L && R <= r) {
    s[node]++;
    sum[node] =
        (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
    return;
  }
  if (R <= l || r <= L) {
    return;
  }
  int mid = (L + R) / 2;
  update(L, mid, 2 * node, l, r);
  update(mid, R, 2 * node + 1, l, r);
  sum[node] = (long long)s[node] * (R - L) + sum[2 * node] + sum[2 * node + 1];
}
long long finds(int l, int r, int node, int x) {
  if (l + 1 == r) {
    return s[node];
  }
  int mid = (l + r) / 2;
  if (x < mid) {
    return (long long)s[node] * (x - l + 1) + finds(l, mid, 2 * node, x);
  }
  return (long long)s[node] * (x - l + 1) + sum[2 * node] +
         finds(mid, r, 2 * node + 1, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(rang, rang + maxn, -1);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(v);
    ger[v].push_back(u);
  }
  ffty(n);
  fill(fir, fir + maxn, inf);
  for (int i = 0; i < n; i++) {
    if (rang[i] != -1) {
      fir[rang[i]] = min(fir[rang[i]], i);
      las[rang[i]] = max(las[rang[i]], i);
    }
  }
  f[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    int c = rang[i];
    if (c == -1) {
      f[i] = f[i + 1];
      continue;
    }
    f[i] = f[i + 1];
    if (fir[rang[i]] == i) {
      f[i] = min(f[i], las[rang[i]]);
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l;
    cin >> l >> r[i];
    l--;
    r[i]--;
    vec[l].push_back(i);
  }
  for (int i = n - 1; i >= 0; i--) {
    update(0, n, 1, i, f[i]);
    for (int j = 0; j < vec[i].size(); j++) {
      ans[vec[i][j]] = finds(0, n, 1, r[vec[i][j]]);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}
