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 long long maxn = long long(3e5) + 5;
const long long mod = 998244353;
const long long inf = long long(2e6) + 5;
inline long long read() {
  char c = getchar();
  int f = 1;
  long long ans = 0;
  while (c > '9' || c < '0') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans * f;
}
struct node {
  node *left, *right;
  long long l, mid, r;
  long long val, nxt;
  node(long long l, long long r) : l(l), r(r) {
    left = right = nullptr;
    mid = (l + r) / 2;
    val = inf;
    nxt = inf;
  }
};
void build(node* root) {
  if (root->l + 1 == root->r) {
    return;
  } else {
    root->left = new node(root->l, root->mid);
    root->right = new node(root->mid, root->r);
    build(root->left);
    build(root->right);
  }
}
void push(node* root) {
  if (root->left != nullptr) {
    root->left->nxt = min(root->left->nxt, root->nxt);
    root->right->nxt = min(root->right->nxt, root->nxt);
  }
  root->val = min(root->val, root->nxt);
}
void set_val(node* root, long long ql, long long qr, long long val) {
  push(root);
  if (root->r <= ql || root->l >= qr) {
    return;
  }
  if (ql <= root->l && root->r <= qr) {
    root->nxt = val;
    return;
  }
  set_val(root->left, ql, qr, val);
  set_val(root->right, ql, qr, val);
}
vector<long long> mxi;
void conclude(node* root) {
  push(root);
  if (root->l + 1 == root->r) {
    mxi[root->l] = root->val;
  } else {
    conclude(root->left);
    conclude(root->right);
  }
}
vector<long long> gr[maxn];
vector<pair<long long, long long> > segs;
vector<long long> way;
vector<long long> used;
void dfs(long long v, long long par) {
  used[v] = 1;
  way.push_back(v);
  for (auto i : gr[v]) {
    if (i == par) continue;
    if (used[i] == 0) {
      dfs(i, v);
    } else if (used[i] == 1) {
      long long pos = way.size() - 1;
      long long mn = i, mx = i;
      while (way[pos] != i) {
        mn = min(mn, way[pos]);
        mx = max(mx, way[pos]);
        pos--;
      }
      segs.push_back({mn, mx});
    }
  }
  used[v] = 2;
  way.pop_back();
}
long long mus1n(long long val) { return val * (val + 1) / 2; }
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    gr[v].push_back(u);
    gr[u].push_back(v);
  }
  used.assign(n, 0);
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      dfs(i, -1);
    }
  }
  node* root = new node(0, n);
  build(root);
  for (auto el : segs) {
    set_val(root, 0, el.first + 1, el.second - 1);
  }
  mxi.assign(n, 0);
  conclude(root);
  for (long long i = 0; i < n - 1; i++) {
    assert(mxi[i] <= mxi[i + 1]);
  }
  vector<long long> pref(1, 0);
  for (long long i = 0; i < n; i++) {
    pref.push_back(pref.back() + mxi[i]);
  }
  long long q;
  cin >> q;
  for (long long tt = 0; tt < q; tt++) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    long long res = pref[r + 1] - pref[l];
    long long left = l - 1, right = r;
    while (right - left > 1) {
      long long mid = (left + right) / 2;
      if (mxi[mid] <= r) {
        left = mid;
      } else {
        right = mid;
      }
    }
    res -= (mxi[right] - r) * (r - right + 1);
    res -= (mus1n(r) - mus1n(l - 1)) - (r - l + 1);
    cout << res << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
