You are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. Let's enumerate vertices from 1 to n. 

You have to answer q queries. Each query is described by a segment of vertices [l; r], and you have to count the number of its subsegments [x; y] (l ≤ x ≤ y ≤ r), such that if we delete all vertices except the segment of vertices [x; y] (including x and y) and edges between them, the resulting graph is bipartite.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — the number of vertices and the number of edges in the graph.

The next m lines describe edges in the graph. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting an edge between vertices ai and bi. It is guaranteed that this graph does not contain edge-simple cycles of even length.

The next line contains a single integer q (1 ≤ q ≤ 3·105) — the number of queries.

The next q lines contain queries. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the query parameters.

Output

Print q numbers, each in new line: the i-th of them should be the number of subsegments [x; y] (li ≤ x ≤ y ≤ ri), such that the graph that only includes vertices from segment [x; y] and edges between them is bipartite.

Examples

Input

6 6
1 2
2 3
3 1
4 5
5 6
6 4
3
1 3
4 6
1 6


Output

5
5
14


Input

8 9
1 2
2 3
3 1
4 5
5 6
6 7
7 8
8 4
7 2
3
1 8
1 4
3 8


Output

27
8
19

Note

The first example is shown on the picture below:

<image>

For the first query, all subsegments of [1; 3], except this segment itself, are suitable.

For the first query, all subsegments of [4; 6], except this segment itself, are suitable.

For the third query, all subsegments of [1; 6] are suitable, except [1; 3], [1; 4], [1; 5], [1; 6], [2; 6], [3; 6], [4; 6].

The second example is shown on the picture below:

<image>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
using uint = unsigned;
using ull = unsigned long long;
template <class t, size_t n>
ostream& operator<<(ostream& os, const array<t, n>& first) {
  return os << vc<t>(first.begin(), first.end());
}
template <int i, class T>
void print_tuple(ostream&, const T&) {}
template <int i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
  if (i) os << ",";
  os << get<i>(t);
  print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  os << "{";
  print_tuple<0, tuple<Args...>, Args...>(os, t);
  return os << "}";
}
template <class t>
void print(t x, int suc = 1) {
  cout << x;
  if (suc == 1) cout << "\n";
  if (suc == 2) cout << " ";
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
vi readvi(int n, int off = 0) {
  vi v(n);
  for (int i = int(0); i < int(n); i++) v[i] = read() + off;
  return v;
}
template <class T>
void print(const vector<T>& v, int suc = 1) {
  for (int i = int(0); i < int(v.size()); i++)
    print(v[i], i == int(v.size()) - 1 ? suc : 2);
}
string readString() {
  string s;
  cin >> s;
  return s;
}
template <class T>
T sq(const T& t) {
  return t * t;
}
void yes(bool ex = true) {
  cout << "Yes"
       << "\n";
  if (ex) exit(0);
}
void no(bool ex = true) {
  cout << "No"
       << "\n";
  if (ex) exit(0);
}
void possible(bool ex = true) {
  cout << "Possible"
       << "\n";
  if (ex) exit(0);
}
void impossible(bool ex = true) {
  cout << "Impossible"
       << "\n";
  if (ex) exit(0);
}
constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
const ll infLL = LLONG_MAX / 3;
const int inf = INT_MAX / 2 - 100;
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }
int botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
ll mask(int i) { return (ll(1) << i) - 1; }
bool inc(int first, int second, int c) {
  return first <= second && second <= c;
}
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll rand_int(ll l, ll r) {
  static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<ll>(l, r)(gen);
}
template <class t>
void myshuffle(vc<t>& first) {
  for (int i = int(0); i < int(int(first.size())); i++)
    swap(first[i], first[rand_int(0, i)]);
}
template <class t>
int lwb(const vc<t>& v, const t& first) {
  return lower_bound(v.begin(), v.end(), first) - v.begin();
}
template <class N>
struct linkcut {
  struct Node {
    using np = Node*;
    np l, r, p;
    bool rev;
    N x;
    Node() : l(0), r(0), p(0), rev(false), x() {}
    void reverse() {
      rev ^= true;
      x.reverse();
    }
    void propagate() {
      if (rev) {
        swap(l, r);
        if (l) l->reverse();
        if (r) r->reverse();
        rev = false;
      }
      if (l) x.push(l->x);
      if (r) x.push(r->x);
      x.clear();
    }
    void update() {
      x.single();
      if (l) x.updatel(l->x);
      if (r) x.updater(r->x);
    }
    int pos() {
      if (p && p->l == this) return -1;
      if (p && p->r == this) return 1;
      return 0;
    }
    void prepare() {
      if (pos()) p->prepare();
      propagate();
    }
    void rotate() {
      np q = p, c;
      if (pos() == 1) {
        c = l;
        l = p;
        p->r = c;
      } else {
        c = r;
        r = p;
        p->l = c;
      }
      if (c) c->p = p;
      p = p->p;
      q->p = this;
      if (p && p->l == q) p->l = this;
      if (p && p->r == q) p->r = this;
      q->update();
    }
    void splay() {
      prepare();
      while (pos()) {
        int first = pos(), second = p->pos();
        if (second && first == second) p->rotate();
        if (second && first != second) rotate();
        rotate();
      }
      update();
    }
    void expose() {
      for (np first = this; first; first = first->p) first->splay();
      for (np first = this; first->p; first = first->p) {
        first->p->r = first;
        first->p->update();
      }
      splay();
    }
    void evert() {
      expose();
      if (l) {
        l->reverse();
        l = 0;
        update();
      }
    }
    void link(np first) {
      evert();
      p = first;
    }
    template <class F, class... Args>
    np find(F f, Args&&... args) {
      if (!(x.*f)(forward<Args>(args)...)) return 0;
      propagate();
      x.single();
      np first = 0;
      if (l) first = l->find(f, forward<Args>(args)...);
      if (first) return first;
      if ((x.*f)(forward<Args>(args)...)) {
        splay();
        return this;
      }
      return r->find(f, forward<Args>(args)...);
    }
    void cutchild() {
      expose();
      r = 0;
      update();
    }
    void cutpar() {
      expose();
      assert(l);
      l->p = 0;
      l = 0;
      update();
    }
  } * x;
  linkcut(int n) { x = new Node[n]; }
  ~linkcut() { delete[] x; }
  using np = typename Node::np;
  int lca(int aa, int bb) {
    np first = x + aa, second = x + bb;
    first->expose();
    second->expose();
    if (!first->p) return -1;
    np d = first;
    while (first->p != second) {
      if (first->pos() == 0) d = first->p;
      first = first->p;
    }
    if (first == second->l)
      return d - x;
    else
      return second - x;
  }
  void link(int first, int second) { x[first].link(x + second); }
  void cutpar(int first) { x[first].cutpar(); }
  void expose(int first) { x[first].expose(); }
  void evert(int first) { x[first].evert(); }
  void expose_path(int first, int second) {
    x[first].evert();
    x[second].cutchild();
  }
  N& operator[](int i) { return x[i].x; }
  template <class F, class... Args>
  int find(int first, F f, Args&&... args) {
    np res = x[first].find(f, forward<Args>(args)...);
    if (res)
      return res - x;
    else
      return -1;
  }
};
struct N {
  void init() {}
  void reverse() {}
  void push(N&) {}
  void clear() {}
  void single() {}
  void updatel(const N&) {}
  void updater(const N&) {}
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int n, m;
  cin >> n >> m;
  vvc<pi> g(n);
  vi used(m);
  for (int i = int(0); i < int(m); i++) {
    int first, second;
    cin >> first >> second;
    first--;
    second--;
    g[first].emplace_back(second, i);
    g[second].emplace_back(first, i);
  }
  vi left(n);
  {
    linkcut<N> lc(n);
    int l = 0, r = 0;
    auto deledge = [&](int first, int second, int i) {
      if (!used[i]) return;
      lc.evert(first);
      lc.cutpar(second);
      used[i] = 0;
    };
    auto delvert = [&]() {
      assert(l < r);
      for (auto e : g[l]) {
        deledge(l, e.first, e.second);
      }
      l++;
    };
    auto addvert = [&]() {
      assert(r < n);
      for (auto e : g[r]) {
        while (inc(l, e.first, r - 1) && lc.lca(r, e.first) != -1) {
          delvert();
        }
        if (inc(l, e.first, r - 1)) {
          lc.link(r, e.first);
          used[e.second] = 1;
        }
      }
      r++;
    };
    for (int i = int(0); i < int(n); i++) {
      addvert();
      left[i] = l;
    }
  }
  void(0);
  vc<ll> sum(n + 1);
  for (int i = int(0); i < int(n); i++) sum[i + 1] = sum[i] + left[i];
  int q;
  cin >> q;
  for (int _ = int(0); _ < int(q); _++) {
    int l, r;
    cin >> l >> r;
    l--;
    ll ans = ll(r - l) * (r - l + 1) / 2;
    int i = max(lwb(left, l), l);
    if (i < r) {
      ans -= sum[r] - sum[i] - ll(r - i) * l;
    }
    print(ans);
  }
}
