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>
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
Shining through the city with a little funk and soul
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x901C
   {
      static ArrayDeque<Integer>[] edges;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         edges = new ArrayDeque[N+1];
         for(int i=1; i <= N; i++)
            edges[i] = new ArrayDeque<Integer>();
         for(int i=0; i < M; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            edges[a].add(b);  edges[b].add(a);
         }
         //preprocess
         int[] buckets = new int[N+1];
         Arrays.fill(buckets, N+1);
         parents = new int[N+1];
         Arrays.fill(parents, -1);
         tag = new int[N+1];
         Arrays.fill(tag, N+N+N);
         cc = 0;
         color = new int[N+1];
         for(int v=1; v <= N; v++)
            if(color[v] == 0)
               dfs(v, 0);
         int[] minCycle = new int[cc];
         int[] maxCycle = new int[cc];
         Arrays.fill(minCycle, N+1);
         for(int v=1; v <= N; v++)
            if(tag[v] != N+N+N)
            {
               minCycle[tag[v]] = Math.min(minCycle[tag[v]], v);
               maxCycle[tag[v]] = Math.max(maxCycle[tag[v]], v);
            }
         for(int c=0; c < cc; c++)
            if(minCycle[c] != N+1)
               buckets[minCycle[c]] = maxCycle[c];
         int[] suffix = new int[N+1];
         int boof = N+1;
         for(int v=N; v >= 1; v--)
         {
            boof = Math.min(boof, buckets[v]);
            suffix[v] = boof;
         }
         long[] psums = new long[N+1];
         psums[1] = suffix[1]-1;
         for(int i=2; i <= N; i++)
            psums[i] = psums[i-1]+suffix[i]-i;
         //buckets[L].add(R) = range [L, R] contains cycle
         int Q = Integer.parseInt(infile.readLine());
         StringBuilder sb = new StringBuilder();
         for(int qw=0; qw < Q; qw++)
         {
            st = new StringTokenizer(infile.readLine());
            int L = Integer.parseInt(st.nextToken());
            int R = Integer.parseInt(st.nextToken());
            long length = R-L+1;
            if(suffix[L] > R)
               sb.append(length*(length+1)/2+"\n");
            else
            {
               int low = L;
               int high = R;
               while(low != high)
               {
                  int mid = (low+high+1)/2;
                  if(suffix[mid] <= R)
                     low = mid;
                  else
                     high = mid-1;
               }
               long res = psums[low]-psums[L-1];
               res += (long)(R-low)*(R-low+1)/2;
               sb.append(res+"\n");
            }
         }
         System.out.print(sb);
      }
      static int cc;
      static int[] tag;
      static int[] parents;
      static int[] color;
      public static void dfs(int curr, int par)
      {
         if(color[curr] == 2)
            return;
         if(color[curr] == 1)
         {
            int head = par;
            tag[curr] = cc;
            while(head != curr)
            {
               tag[head] = cc;
               head = parents[head];
            }
            cc++;
            return;
         }
         parents[curr] = par;
         color[curr] = 1;
         for(int next: edges[curr])
            if(next != par)
               dfs(next, curr);
         color[curr] = 2;
      }
   }