#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, m;
vector<int> adj[300000];
stack<int> st;
int vis[300000];
int mx[300000];
void dfs(int no, int p) {
  vis[no] = -1;
  st.push(no);
  for (int i = 0; i < (int((adj[no]).size())); ++i) {
    int to = adj[no][i];
    if (to == p) continue;
    if (vis[to] == -1) {
      vector<int> thiscyc;
      int mini = n + 1;
      int maxi = -1;
      while (!st.empty() && st.top() != to) {
        mini = min(mini, st.top());
        maxi = max(maxi, st.top());
        vis[st.top()] = 1;
        st.pop();
      }
      if (!st.empty()) {
        mini = min(mini, st.top());
        maxi = max(maxi, st.top());
        vis[st.top()] = 1;
        st.pop();
      }
      mx[mini] = maxi - 1;
    } else if (vis[to] == 0) {
      dfs(to, no);
    }
  }
}
long long pref1[300000];
long long pref2[300000];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < (n); ++i) {
    mx[i] = n - 1;
  }
  for (int i = 0; i < (n); ++i) {
    if (!vis[i]) dfs(i, -1);
  }
  for (int i = n - 2; i >= 0; i--) {
    mx[i] = min(mx[i], mx[i + 1]);
  }
  for (int i = 0; i < (n); ++i) {
    pref1[i] = mx[i] - i + 1 + ((i == 0) ? 0 : pref1[i - 1]);
    pref2[i] = -i + 1 + ((i == 0) ? 0 : pref2[i - 1]);
  }
  int q;
  scanf("%d", &q);
  for (int query = 0; query < (q); ++query) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    int lo = l;
    int hi = r;
    while (lo < hi) {
      int mid = (lo + hi + 1) / 2;
      if (mx[mid] <= r) {
        lo = mid;
      } else {
        hi = mid - 1;
      }
    }
    long long p1 = 0;
    long long p2 = 0;
    if (mx[l] > r) {
      p1 = 0;
      p2 = pref2[r] - ((l - 1 < 0) ? 0 : pref2[l - 1]) +
           (long long)r * ((long long)r - l + 1);
    } else {
      assert(mx[lo] <= r);
      p1 = pref1[lo] - ((l - 1 < 0) ? 0 : pref1[l - 1]);
      p2 = pref2[r] - pref2[lo] + (long long)r * ((long long)r - lo);
    }
    long long tans = p1 + p2;
    cout << tans << endl;
  }
}
