#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 4;
int prec[maxN];
void makefirst(int x) {
  int y = 0;
  int t = prec[x];
  while (x) {
    prec[x] = y;
    y = x;
    x = t;
    t = prec[x];
  }
}
bool same(int x, int y) {
  makefirst(x);
  for (; x != y && y; y = prec[y])
    ;
  return x == y;
}
void unite(int x, int y) {
  makefirst(x);
  prec[x] = y;
}
void split(int x, int y) {
  makefirst(x);
  prec[y] = 0;
}
int n, m, q;
vector<int> v[maxN];
int _right[maxN];
bool canAdd(int st, int dr) {
  stack<pair<int, int> > stk;
  for (auto it : v[dr])
    if (it >= st && it <= dr) {
      if (same(dr, it)) {
        while (!stk.empty()) {
          int a = stk.top().first;
          int b = stk.top().second;
          stk.pop();
          split(a, b);
        }
        return false;
      } else {
        stk.push(make_pair(it, dr));
        unite(it, dr);
      }
    }
  return true;
}
void get_right() {
  int st = 1;
  int dr = 2;
  while (st <= n && dr <= n) {
    if (canAdd(st, dr))
      dr++;
    else {
      for (auto it : v[st])
        if (it >= st && it <= dr) split(it, st);
      _right[st] = dr;
      st++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!_right[i]) _right[i] = n + 1;
}
long long sum[maxN];
long long query(int lef, int rig) {
  int st = lef;
  int dr = rig;
  while (st < dr) {
    int mij = (st + dr) / 2;
    if (_right[mij] > rig)
      dr = mij;
    else
      st = mij + 1;
  }
  long long len = rig - st + 1;
  long long res = 0;
  res += len * (len + 1) / 2;
  res += sum[st - 1] - sum[lef - 1];
  return res;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  get_right();
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + 1LL * _right[i] - 1LL * i;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int pr, ul;
    scanf("%d %d", &pr, &ul);
    printf("%I64d\n", query(pr, ul));
  }
  return 0;
}
