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;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
struct Edge {
  int from, to, weight;
};
template <class T, class OP, class PROP>
class Lazy_Segment_Tree {
 public:
  vector<T> data, lazy;
  vector<bool> isupd;
  int n;
  Lazy_Segment_Tree(int a) : n(1) {
    while (n < a) n *= 2;
    data.resize(n * 2 - 1);
    lazy.resize(n * 2 - 1);
    isupd.resize(n * 2 - 1);
  }
  void prop(int num, int s) {
    if (isupd[num]) {
      data[num] = PROP()(data[num], lazy[num], 1, s);
      if (num < n - 1) {
        lazy[num * 2 + 1] = PROP()(lazy[num * 2 + 1], lazy[num]);
        lazy[num * 2 + 2] = PROP()(lazy[num * 2 + 2], lazy[num]);
        isupd[num * 2 + 1] = 1;
        isupd[num * 2 + 2] = 1;
      }
      lazy[num] = T();
      isupd[num] = 0;
    }
  }
  void op(int a, int b, T v, int num = 0, int base = 1) {
    int l = (num + 1 - base) * (n / base), r = l + n / base;
    prop(num, r - l);
    if (a == l && b == r) {
      isupd[num] = 1;
      lazy[num] = PROP()(lazy[num], v);
      prop(num, r - l);
    } else {
      int nr = (l + r) / 2;
      if (nr > a) op(a, min(b, nr), v, num * 2 + 1, base * 2);
      if (nr < b) op(max(a, nr), b, v, num * 2 + 2, base * 2);
      prop(num * 2 + 1, (r - l) / 2), prop(num * 2 + 2, (r - l) / 2);
      data[num] = OP()(data[num * 2 + 1], data[num * 2 + 2]);
    }
  }
  T query(int a, int b, int num = 0, int base = 1) {
    int l = (num + 1 - base) * (n / base), r = l + n / base;
    prop(num, r - l);
    if (a == l && b == r)
      return data[num];
    else {
      int nr = (l + r) / 2;
      T ret = T();
      if (nr > a) ret = OP()(ret, query(a, min(b, nr), num * 2 + 1, base * 2));
      if (nr < b) ret = OP()(ret, query(max(a, nr), b, num * 2 + 2, base * 2));
      return ret;
    }
  }
};
template <class T>
class ADD {
 public:
  T operator()(const T a, const T b, const int ra = 1, int rb = 1) {
    return a * ra + b * rb;
  }
};
template <class T>
class UPD {
 public:
  T operator()(const T a, const T b, const int ra = 1, int rb = 1) { return b; }
};
template <class T>
class RMQ {
 public:
  T operator()(const T a, const T b) { return min(a, b); }
};
template <class T>
class SUM {
 public:
  T operator()(const T a, const T b) { return a + b; }
};
struct N {
 public:
  long long num;
  N(long long num) : num(num) {}
  N() : num(0) {}
  N operator+(const N obj) const { return N(obj.num + num); }
  N operator*(const N obj) const { return N(obj.num * num); }
  bool operator<(const N obj) const { return obj.num > num; }
};
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<Edge>> g(n);
  for (int i = (0); (m) > i; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    g[a].push_back({a, b, 1});
    g[b].push_back({b, a, 1});
  }
  vector<pair<int, int>> circle;
  vector<int> visited(n, -1);
  int vn = 0;
  stack<int> st;
  function<void(int, int)> dfs = [&](int c, int p) {
    if (visited[c] != -1) {
      if (visited[c] < visited[p]) {
        stack<int> buf;
        int Min = INT_MAX, Max = INT_MIN;
        while (1) {
          int cur = st.top();
          buf.push(cur);
          st.pop();
          Min = min(Min, cur);
          Max = max(Max, cur);
          if (cur == c) break;
        }
        circle.push_back({Min, Max});
        while (buf.size()) st.push(buf.top()), buf.pop();
      }
      return;
    }
    visited[c] = vn;
    vn++;
    st.push(c);
    for (auto itr : g[c])
      if (itr.to != p) dfs(itr.to, c);
    st.pop();
  };
  for (int i = (0); (n) > i; i++) {
    if (visited[i] == -1) dfs(i, -1);
  }
  cout << endl;
  vector<int> kyo(n);
  set<pair<int, int>> cir;
  for (auto itr : circle) cir.insert({itr.second, itr.first});
  sort((circle).begin(), (circle).end());
  int cc = 0;
  for (int i = (0); (n) > i; i++) {
    if (cir.size() == 0) {
      kyo[i] = n;
    } else
      kyo[i] = cir.begin()->first;
    for (; circle.size() > cc; cc++) {
      if (circle[cc].first > i) break;
      cir.erase({circle[cc].second, circle[cc].first});
    }
  }
  vector<long long> rui(n + 1);
  for (int i = (0); (n) > i; i++) {
    printf("%d ", kyo[i]);
    rui[i + 1] = rui[i] + (kyo[i] - i);
  }
  printf("");
  int q;
  cin >> q;
  for (int i = (0); (q) > i; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    int m = lower_bound((kyo).begin(), (kyo).end(), r) - kyo.begin();
    long long ans = rui[min(r, m)] - rui[l];
    if (m < r) ans += ((r * 1LL - m) + 1) * (r - m) / 2;
    cout << ans << endl;
  }
  return 0;
}
