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 ga(int N, int *A) {
  for (int i(0); i < N; i++) scanf("%d", A + i);
}
struct nd {
  nd() : P(0), pp(0), f(0) {
    *C = C[1] = 0;
    fix();
  }
  nd *P, *C[2], *pp;
  int f;
  void fix() {
    if (*C) C[0]->P = this;
    if (C[1]) C[1]->P = this;
  }
  void psh() {
    if (!f) return;
    f = 0, swap(*C, C[1]);
    if (*C) C[0]->f ^= 1;
    if (C[1]) C[1]->f ^= 1;
  }
  int up() { return !P ? -1 : !(P->C[0] == this); }
  void zig(int c) {
    nd *X = C[c];
    if ((X->P = P)) P->C[up()] = X;
    C[c] = X->C[1 - c], X->C[1 - c] = this;
    fix();
    X->fix();
    if (P) P->fix();
    swap(pp, X->pp);
  }
  void zA(int c) {
    nd *X = C[c], *Y = X->C[c];
    if ((Y->P = P)) P->C[up()] = Y;
    C[c] = X->C[1 - c], X->C[c] = Y->C[1 - c], Y->C[1 - c] = X;
    X->C[1 - c] = this, fix(), X->fix(), Y->fix();
    if (P) P->fix();
    swap(pp, Y->pp);
  }
  void zB(int c) {
    nd *X = C[c], *Y = X->C[1 - c];
    if ((Y->P = P)) P->C[up()] = Y;
    C[c] = Y->C[1 - c], X->C[1 - c] = Y->C[c], Y->C[1 - c] = this;
    Y->C[c] = X, fix(), X->fix(), Y->fix();
    if (P) P->fix();
    swap(pp, Y->pp);
  }
  nd *splay() {
    for (psh(); P;) {
      if (P->P) P->P->psh();
      P->psh(), psh();
      int c1 = up(), c2 = P->up();
      if (!~c2)
        P->zig(c1);
      else if (c1 == c2)
        P->P->zA(c1);
      else
        P->P->zB(c2);
    }
    return this;
  }
  nd *lst() { return psh(), C[1] ? C[1]->lst() : splay(); }
  nd *fst() { return psh(), *C ? C[0]->fst() : splay(); }
};
struct lc {
  lc(int N) : cd(N) {}
  void lnk(int u, int v) {
    if (con(u, v)) return;
    rt(v), cd[v].pp = &cd[u];
  }
  void cut(int u, int v) {
    if (!con(u, v)) return;
    rt(u), cd[v].splay();
    if (cd[v].pp)
      cd[v].pp = 0;
    else
      cd[v].C[0] = cd[v].C[0]->P = 0, cd[v].fix();
  }
  bool con(int u, int v) {
    nd *nu = acc(u)->fst(), *nv = acc(v)->fst();
    return nu == nv;
  }
  void rt(int u) {
    acc(u), cd[u].splay();
    if (*cd[u].C)
      cd[u].C[0]->P = 0, cd[u].C[0]->f ^= 1, cd[u].C[0]->pp = &cd[u],
      cd[u].C[0] = 0, cd[u].fix();
  }
  nd *acc(int u) {
    nd *x, *pp;
    for (x = cd[u].splay(); x->pp; x = pp) {
      pp = x->pp->splay(), x->pp = 0;
      if (pp->C[1]) pp->C[1]->P = 0, pp->C[1]->pp = pp;
      pp->C[1] = x, pp->fix();
    }
    return x;
  }
  vector<nd> cd;
} T(3e5 + 5);
long long S[333333];
int N, M, a, b, I, V[333333];
vector<int> g[333333];
int gt(int b, int I) {
  return lower_bound(g[I].begin(), g[I].end(), b) - g[I].begin();
}
bool ok(int b, int I) {
  int J = gt(b, I), K = J - 1;
  while (++K < (int)g[I].size() && g[I][K] < I) {
    if (T.con(g[I][K], I)) {
      while (--K >= J) T.cut(g[I][K], I);
      return 0;
    }
    T.lnk(g[I][K], I);
  }
  return 1;
}
int main(void) {
  scanf("%d%d", &N, &M);
  for (int i(0); i < M; i++)
    scanf("%d%d", &a, &b), g[--a].push_back(--b), g[b].push_back(a);
  for (int i(0); i < N; i++) sort(g[i].begin(), g[i].end());
  for (int i(0); i < N; i++) {
    while (I < N && ok(i, I)) ++I;
    a = gt(i, i) - 1, S[i] = I - i + (i ? S[i - 1] : 0), V[i] = I;
    while (++a < (int)g[i].size() && g[i][a] < I) T.cut(i, g[i][a]);
  }
  int _;
  scanf("%d", &_);
  for (int i(0); i < _; i++) {
    scanf("%d%d", &a, &b), --a, --b, I = upper_bound(V, V + N, b) - V;
    if (I <= a)
      printf("%lld\n", ((b - a + 1) * (b - a + 1 + 1ll) / 2));
    else
      printf("%lld\n", ((b - I + 1) * (b - I + 1 + 1ll) / 2) +
                           (S[I - 1] - (a ? S[a - 1] : 0)));
  }
  return 0;
}
