#include <bits/stdc++.h>
using namespace std;
int n, m, at[300005], v[300005], to[300005], ta, tb, tc;
vector<int> ne[300005], x[20];
vector<long long> y[20];
vector<vector<int> > cy;
pair<int, int> p[300005];
pair<int, pair<int, int> > q[300005];
long long ans[300005];
int dfs(int a, int b) {
  int re = -1;
  v[a] = 1;
  for (int i = 0; i < ne[a].size(); i++)
    if (ne[a][i] != b)
      if (v[ne[a][i]] == 1) {
        re = ne[a][i];
        at[ne[a][i]] = at[a] = cy.size();
        cy.push_back(vector<int>());
        cy.back().push_back(ne[a][i]);
        cy.back().push_back(a);
      } else if (!v[ne[a][i]]) {
        int ret = dfs(ne[a][i], a);
        if (ret != -1 && ret != a) {
          at[a] = at[ret];
          cy[at[ret]].push_back(a);
          re = ret;
        }
      }
  v[a] = 2;
  return re;
}
long long f1(int a, int b, int c, int d) {
  if (((1 << (c)) * (d)) == a && ((1 << (c)) * (d + 1)) == b)
    return y[c][d] + (long long)tb * (b - a - x[c][d]) -
           (long long)(a + b - 1) * (b - a) / 2;
  c--;
  d = d * 2 + 1;
  if (b <= ((1 << (c)) * (d))) return f1(a, b, c, d - 1);
  if (a >= ((1 << (c)) * (d))) return f1(a, b, c, d);
  return f1(a, ((1 << (c)) * (d)), c, d - 1) + f1(((1 << (c)) * (d)), b, c, d);
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d", &ta, &tb);
    ne[ta].push_back(tb);
    ne[tb].push_back(ta);
  }
  for (int i = 1; i <= n; i++) {
    at[i] = -1;
    to[i - 1] = n;
  }
  for (int i = 1; i <= n; i++)
    if (!v[i]) dfs(i, 0);
  for (int i = 1; i <= n; i++) ne[i].clear();
  for (int i = 0; i < cy.size(); i++) {
    sort(cy[i].begin(), cy[i].end());
    to[cy[i][0] - 1] = cy[i].back() - 1;
  }
  cy.clear();
  for (int i = n - 2; i >= 0; i--) to[i] = min(to[i], to[i + 1]);
  for (int i = 0; i < n; i++) {
    ta = i;
    p[i] = make_pair(to[i], i);
    for (int j = 0; j < 20; j++) {
      if (ta == y[j].size()) {
        y[j].push_back(0);
        x[j].push_back(0);
      }
      ta /= 2;
    }
  }
  sort(p, p + n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &ta, &tb);
    q[i] = make_pair(tb, make_pair(i, ta - 1));
  }
  sort(q, q + m);
  for (int i = 0; i < m; i++) {
    while (tc < n && p[tc].first < q[i].first) {
      ta = p[tc].second;
      for (int j = 0; j < 20; j++) {
        x[j][ta]++;
        y[j][ta] += p[tc].first;
        ta /= 2;
      }
      tc++;
    }
    tb = q[i].first;
    ans[q[i].second.first] = f1(q[i].second.second, q[i].first, 19, 0);
  }
  for (int i = 0; i < m; i++) printf("%lld\n", ans[i]);
  return 0;
}
