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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define in(x); { for (auto &qwertyuiop : x) cin >> qwertyuiop; }
#define out(x); { for (auto qwertyuiop : x) cout << qwertyuiop << ' '; cout << endl; }
//#define int long long

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int INF = 1e9;
const long long INFll = 2e18;
const int base1 = 239;
const int base2 = 179;
const int mod = 998244353;
const int MAXN = 2e5;

vector <int> g[400000];
int d[400000];
int up[400000];
bool used[400000];

bool bridge(int v, int p) {
    used[v] = true;
    up[v] = d[v] = d[p] + 1;

    vector <bool> br(g[v].size());
    for (int j = 0; j < g[v].size(); j++) {
        int i = g[v][j];
        if (i != p) {
            if (used[i]) {
                up[v] = min(up[v], d[i]);
            } else {
                if (bridge(i, v))
                    br[j] = true;
                up[v] = min(up[v], up[i]);
            }
        }
    }

    bool p_br = (up[v] == d[v]);
    if (p_br) {
        for (int i = 0; i < g[v].size(); i++) {
            if (g[v][i] == p)
                br[i] = true;
        }
    }

    vector <int> ng;
    for (int i = 0; i < g[v].size(); i++) {
        if (!br[i])
            ng.pb(g[v][i]);
    }

    g[v] = ng;
    return p_br;
}

int color[400000];
int cc;

void dfs(int v) {
    used[v] = true;
    color[v] = cc;
    for (int i : g[v]) {
        if (!used[i])
            dfs(i);
    }
}

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        g[x].pb(y); g[y].pb(x);
    }

    for (int i = 1; i <= n; i++) {
        if (!used[i])
            bridge(i, 0);
    }

    fill(used, used + 400000, false);
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            if (g[i].empty()) {
                color[i] = -1;
            } else {
                dfs(i);
                cc++;
            }
        }
    }

    vector <int> l(cc), r(cc);
    fill(all(l), n);
    fill(all(r), 1);
    for (int i = 1; i <= n; i++) {
        if (color[i] == -1)
            continue;
        l[color[i]] = min(l[color[i]], i);
        r[color[i]] = max(r[color[i]], i);
    }

    vector <int> last_l(n + 1);
    if (color[1] != -1)
        last_l[1] = (r[color[1]] == 0 ? 1 : 0);
    else
        last_l[1] = 0;
    for (int i = 2; i <= n; i++) {
        last_l[i] = last_l[i - 1];
        if (color[i] == -1)
            continue;
        if (r[color[i]] == i)
            last_l[i] = max(last_l[i], l[color[i]]);
    }

    vector <int> mxr(n + 1), mxlensum(n + 1);
    for (int i = 1; i <= n; i++) {
        int L = i, R = n + 1;
        while (R - L > 1) {
            int M = (L + R) / 2;
            if (last_l[M] < i)
                L = M;
            else
                R = M;
        }
        mxr[i] = L;
        mxlensum[i] = mxlensum[i - 1] + L - i + 1;
    }

    //out(mxr);
    //out(mxlensum);

    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int ql, qr; cin >> ql >> qr;
        int L = ql - 1, R = qr + 1;
        while (R - L > 1) {
            int M = (L + R) / 2;
            if (mxr[M] > qr)
                R = M;
            else
                L = M;
        }
        //cout << L << endl;
        cout << mxlensum[L] - mxlensum[ql - 1] + (qr - L) * (qr - L + 1) / 2 << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
}
