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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define sz size()
#define y1 dfsdsfsdfsd
#define next fdsfsdfjkl
#define endl "\n"
#define int long long
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
double pi = acos(-1.0);
const int inf = 1e9+7;
const ll INF = 1e18+7;
/////////////////////////////////////////

int n,m;

vector<int>g[300300];
int q;

vector< pair<int,int> > vi;


vector< pair<int,int> > cycles;

vector<int> roll_back;

int used[300300];

int h[300300];

int bad[300300];

int used2[300300];
int cycle_cnt = 1;
void dfs(int v,int lvl,int p)
{

    //cout << v << endl;
    used[v] = 1;
    h[lvl] = v;

    for(int i=0;i<g[v].sz;i++)
    {
        int t = g[v][i];

        if(used[t]==1 && t!=p)
        {

            //cout<< "tp " << v<<" "<< t << " " << p <<endl;
            //cout << t <<endl;

            int mx = 0;
            int mn = 500500;



            for(int j=lvl;j>=0;j--)
            {
                //cout<< h[j] << " ";
                mx = max(h[j],mx);
                mn = min(h[j],mn);


                if(h[j]==t) break;
            }


            //cout<<endl;
            cycles.pb(mp(mn,mx));
        }
        else if(used[t]==0 && t!=p)
        {
            dfs(t,lvl+1,v);
        }

    }

    used[v] = 2;
}



int check(int l,int r)
{
    for(int i=0;i<vi.sz;i++)
    {
        if(cycles[i].fi>=l && cycles[i].se<=r) return 0;
    }

    return 1;
}



vector<int>right;

int mx_r[300300];


set< int >L;
set< int >R;


int usedr[300300];
int usedl[300300];


int pref_r[300300];





vector<int> e[300300];
main(){speed;
    cin>>n>>m;

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

    cin>>q;
    for(int i=0;i<q;i++)
    {
        int l,r;
        cin>>l>>r;
        vi.pb(mp(l,r));
    }

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

  //  cout<< endl << endl;
    for(int i=0;i<cycles.sz;i++)
    {
        int l = cycles[i].fi;
        int r = cycles[i].se;

       // right.pb(r);
        //cout<<l<<" "<<r<<endl;

        e[l].pb(r);
    }

    int ind = 0;

    //cout<<endl;
    //cout<<endl;


    //cout<<endl;


    //cout<<endl;

    /*for(int i=0;i<vi.sz;i++)
    {
        int l = vi[i].fi;
        int r = vi[i].se;

        int ans = 0;
        for(int x=l;x<=r;x++)
        {
            for(int y=x;y<=r;y++)
            {
                if(check(x,y)) ans++;
            }
        }

        cout<< ans << endl;
    }*/
    //cout<<endl;
//    cout<<"# ";
 //   for(int i=1;i<=n;i++) cout<<mx_r[i]<<" ";
    int mn = inf;
    for(int i=n;i>=1;i--)
    {

        for(int j=0;j<e[i].sz;j++)
        {
            int t = e[i][j];

            mn = min(mn,t);
        }
        mx_r[i] = mn - 1;
    }

    for(int i=1;i<=n;i++) pref_r[i] = pref_r[i-1] + (mx_r[i] - i + 1);


    // for(int i=1;i<=n;i++) cout<<mx_r[i]<<" ";

     // cout<<endl;
 //   for(int i=1;i<=n;i++) cout<<pref_r[i]<<" ";

    //cout<<endl;
    //cout<<endl;
    for(int i=0;i<vi.sz;i++)
    {
        int l = vi[i].fi;
        int r = vi[i].se;

        int f = l;
        int s = r;
        int sum = 0;

        int ans = 0;
        while(l<=r)
        {
            int mid = (l+r)>>1;

            if(mx_r[mid]<=s)
            {
                ans = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }

        //cout<<ans<<endl;

        int t = s - ans ;
        t = max(0ll,t);

        sum = t*(t+1)/2;



        int q = pref_r[ans] - pref_r[f-1];
        //cout<<q<<endl;
        if(!ans) q = 0;

        sum += q;

        cout<<sum<<endl;
    }

}
/*

7 8
1 2
2 3
1 3
3 4
4 5
4 7
5 6
6 7
*/


/*
12 15
1 2
2 3
1 3
2 4
4 5
5 6
4 6
6 7
7 9
8 9
7 8
9 10
10 12
10 11
11 12
*/

/*
20 25
20 19
20 18
18 19
18 2
1 2
2 3
3 4
4 5
1 5
1 6
7 6
6 8
7 8
5 11
9 11
9 10
10 11
3 15
15 17
15 16
16 17
4 12
12 13
12 14
13 14

*/
