#include <bits/stdc++.h>
using namespace std;
int const N = 300000;
int n, m, q, cl[N + 1];
long long an[N], s[N << 2], z[N << 2];
vector<pair<int, int> > qu[N + 1];
vector<int> g[N + 1], bad[N + 1];
bool st[N + 1];
pair<int, int> go(int v = 1, int p = 0) {
  pair<int, int> an(-1, -1);
  cl[v] = 1;
  for (int i = 0; i < (int)(g[v].size()); ++i) {
    int u = g[v][i];
    if (u == p || cl[u] == 2) continue;
    if (cl[u] == 1)
      an = make_pair(v, v), st[u] = true;
    else {
      pair<int, int> t = go(u, v);
      if (t.first != -1) an = t;
    }
  }
  cl[v] = 2;
  if (an.first != -1)
    an.first = min(an.first, v), an.second = max(v, an.second);
  if (st[v]) {
    bad[an.second].push_back(an.first);
    return make_pair(-1, -1);
  }
  return an;
}
inline void sl(int id, int l, int r) {
  if (!z[id]) return;
  int m = l + r >> 1, a = id << 1, b = a | 1;
  s[a] += z[id] * (m - l);
  s[b] += z[id] * (r - m);
  z[a] += z[id];
  z[b] += z[id];
  z[id] = 0;
}
void ad(int x, int y, int l = 1, int r = n + 1, int id = 1) {
  if (l >= y || r <= x) return;
  if (l >= x && r <= y) {
    s[id] += r - l, ++z[id];
    return;
  }
  sl(id, l, r);
  int m = l + r >> 1, a = id << 1, b = a | 1;
  ad(x, y, l, m, a);
  ad(x, y, m, r, b);
  s[id] = s[a] + s[b];
}
long long gt(int x, int y, int l = 1, int r = n + 1, int id = 1) {
  if (l >= y || r <= x) return 0;
  if (l >= x && r <= y) return s[id];
  sl(id, l, r);
  int m = l + r >> 1, a = id << 1, b = a | 1;
  return gt(x, y, l, m, a) + gt(x, y, m, r, b);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i < (int)(n + 1); ++i)
    if (cl[i] == 0) go(i);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < (int)(q); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    qu[r].push_back(make_pair(l, i));
  }
  int mn = 0;
  for (int i = 1; i < (int)(n + 1); ++i) {
    for (int j = 0; j < (int)(bad[i].size()); ++j) mn = max(mn, bad[i][j]);
    ad(mn + 1, i + 1);
    for (int j = 0; j < (int)(qu[i].size()); ++j)
      an[qu[i][j].second] = gt(qu[i][j].first, i + 1);
  }
  for (int i = 0; i < (int)(q); ++i) printf("%lld\n", an[i]);
}
