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;
void readi(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readll(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
void writes(string s) { puts(s.c_str()); }
void writeln() { writes(""); }
void writei(int x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
void writell(long long x) {
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
long long qp(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long z = qp(x, y / 2);
  z = z * z % 1000000007;
  if (y & 1) z = z * x % 1000000007;
  return z;
}
long long n, m, q, i, j, cnt, vis[600005], vis2[600005], col[600005], top,
    mx[600005], mi[600005], ans[600005], ans2[600005];
vector<pair<long long, long long> > wyx[600005];
long long st[600005];
bool dfs(long long x, long long fa) {
  vis[x] = 1;
  long long i;
  for (i = 0; i < wyx[x].size(); i++) {
    if (wyx[x][i].first == fa) continue;
    st[++top] = x;
    vis2[x] = 1;
    if (!vis[wyx[x][i].first]) {
      if (dfs(wyx[x][i].first, x)) return 1;
    } else {
      cnt++;
      while (top && st[top] != wyx[x][i].first) {
        col[st[top--]] = cnt;
      }
      col[st[top--]] = cnt;
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    wyx[x].push_back(make_pair(y, i));
    wyx[y].push_back(make_pair(x, i));
  }
  for (i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  memset(mi, 22, sizeof(mi));
  for (i = 1; i <= n; i++) {
    mx[col[i]] = max(mx[col[i]], i);
    mi[col[i]] = min(mi[col[i]], i);
  }
  for (i = 1; i <= n; i++) {
    while (j < n &&
           ((!col[j + 1]) || (j + 1 < mx[col[j + 1]]) || (i > mi[col[j + 1]])))
      j++;
    ans2[i] = j - i + 1 + ans2[i - 1];
    ans[i] = j;
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    long long x, y;
    cin >> x >> y;
    int t = upper_bound(ans + 1, ans + n + 1, y) - ans;
    t--;
    cout << ans2[t] - ans2[x - 1] + (y - t) * (y - t + 1) / 2 << endl;
  }
  return 0;
}
