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;
int n, m;
basic_string<int> e[300005], ee[300005];
bool v[300005], inst[300005];
int p[300005], rr[300005];
void mx(int& x, int y) { x = max(x, y); }
void mn(int& x, int y) { x = min(x, y); }
void dfs(int x) {
  v[x] = 1;
  inst[x] = 1;
  for (int y : e[x]) {
    if (!v[y]) {
      p[y] = x;
      dfs(y);
    } else if (inst[y] && y != p[x]) {
      int lo = y, hi = y;
      for (int i = x; i != y; i = p[i]) mn(lo, i), mx(hi, i);
      mx(rr[hi], lo);
    }
  }
  inst[x] = 0;
}
template <int MAXN>
struct segtree_lazy {
  struct updater {
    int x;
    updater(int x = 0) : x(x) {}
    updater& operator+=(const updater& other) {
      x += other.x;
      return *this;
    }
    operator bool() const { return x != 0; }
  };
  struct node_t {
    long long x, len;
    node_t() : x(0), len(0) {}
    node_t(int x) : x(x), len(1) {}
    node_t& operator+=(const node_t& other) {
      x += other.x;
      len += other.len;
      return *this;
    }
    node_t& operator+=(const updater& other) {
      x += other.x * len;
      return *this;
    }
    node_t operator+(const node_t& other) const {
      node_t tmp = *this;
      tmp += other;
      return tmp;
    }
  };
  node_t a[2 * MAXN];
  updater b[2 * MAXN];
  segtree_lazy() {
    for (int i = 1; i <= MAXN; i++) {
      a[i + MAXN - 1] = node_t(0);
    }
    for (int i = MAXN - 1; i > 0; i--) {
      a[i] = a[2 * i] + a[2 * i + 1];
    }
  }
  void push(int i) {
    if (b[i]) {
      a[i] += b[i];
      if (i < MAXN) {
        b[2 * i] += b[i];
        b[2 * i + 1] += b[i];
      }
      b[i] = updater();
    }
  }
  node_t get(int l, int r, int node = 1, int nl = 1, int nr = MAXN) {
    push(node);
    if (r < nl || nr < l) {
      return node_t();
    }
    if (l <= nl && nr <= r) {
      return a[node];
    }
    int nm = (nl + nr) >> 1;
    return get(l, r, 2 * node, nl, nm) + get(l, r, 2 * node + 1, nm + 1, nr);
  }
  void update(int l, int r, updater val, int node = 1, int nl = 1,
              int nr = MAXN) {
    push(node);
    if (r < nl || nr < l) {
      return;
    }
    if (l <= nl && nr <= r) {
      b[node] += val;
      push(node);
      return;
    }
    int nm = (nl + nr) >> 1;
    update(l, r, val, 2 * node, nl, nm);
    update(l, r, val, 2 * node + 1, nm + 1, nr);
    a[node] = a[2 * node] + a[2 * node + 1];
  }
};
segtree_lazy<524288> drvo;
int q;
long long ans[300005];
int ql[3000005], qr[300005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    e[u] += v;
    e[v] += u;
  }
  for (int i = 1; i <= n; i++) {
    if (!v[i]) {
      p[i] = i;
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++) rr[i] = max(rr[i], rr[i - 1]);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> ql[i] >> qr[i];
    ee[qr[i]] += i;
  }
  for (int i = 1; i <= n; i++) {
    drvo.update(rr[i] + 1, i, 1);
    for (int j : ee[i]) ans[j] = drvo.get(ql[j], i).x;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
}
