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>
import java.io.*;
import java.util.*;
import java.math.*;

public class C implements Runnable {
	private static BufferedReader in;
	private static PrintWriter out;
	private static StringTokenizer st;
	private static Random rnd;

	int verticesCount;
	int edgesCount;

	int[] firstEdge, nextEdge, goesTo;

	boolean[] used;

	int timer;
	int[] tin, fup;
	ArrayList<Long> bridges;

	int[] cmpId, cmpSize, cmpEdges;

	long getBridge(int u, int v) {
		int a = Math.min(u, v);
		int b = Math.max(u, v);
		return (long) (verticesCount) * a + b;
	}

	void dfsBridge(int v, int p) {
		used[v] = true;
		tin[v] = fup[v] = timer++;
		for (int id = firstEdge[v]; id != -1; id = nextEdge[id]) {
			int to = goesTo[id];
			if (to == p)
				continue;
			if (used[to]) {
				fup[v] = Math.min(fup[v], tin[to]);
			} else {
				dfsBridge(to, v);
				fup[v] = Math.min(fup[v], fup[to]);
				if (fup[to] > tin[v]) {
					long bridge = getBridge(v, to);
					bridges.add(bridge);
				}
			}
		}
	}

	boolean isBridge(int u, int v) {
		long bridge = getBridge(u, v);
		return Collections.binarySearch(bridges, bridge) >= 0;
	}

	void dfsMark(int u, int c) {
		used[u] = true;
		cmpId[u] = c;
		cmpSize[c]++;
		for (int id = firstEdge[u]; id != -1; id = nextEdge[id]) {
			int v = goesTo[id];
			if (used[v])
				continue;
			if (!isBridge(u, v)) {
				dfsMark(v, c);
			}
		}
	}

	static class Restriction implements Comparable<Restriction> {
		int greater, lower, minAfter;

		public Restriction(int greater, int lower) {
			this.greater = greater;
			this.lower = lower;
			this.minAfter = lower;
		}

		public int compareTo(Restriction other) {
			return Integer.compare(greater, other.greater);
		}
	}

	private void solve() throws IOException {
		verticesCount = nextInt();
		edgesCount = nextInt();
		// verticesCount = 300000;
		// edgesCount = verticesCount - 1;
		firstEdge = new int[verticesCount];
		nextEdge = new int[2 * edgesCount];
		goesTo = new int[2 * edgesCount];
		Arrays.fill(firstEdge, -1);
		Arrays.fill(nextEdge, -1);
		for (int i = 0; i < edgesCount; i++) {
			int u = nextInt() - 1;
			int v = nextInt() - 1;
			// int u = i;
			// int v = i + 1;
			// int u = rnd.nextInt(verticesCount);
			// int v = rnd.nextInt(verticesCount);

			nextEdge[2 * i] = firstEdge[u];
			nextEdge[2 * i + 1] = firstEdge[v];
			goesTo[2 * i] = v;
			goesTo[2 * i + 1] = u;
			firstEdge[u] = 2 * i;
			firstEdge[v] = 2 * i + 1;
		}
		used = new boolean[verticesCount];
		tin = new int[verticesCount];
		fup = new int[verticesCount];
		bridges = new ArrayList<>(edgesCount);
		for (int i = 0; i < verticesCount; i++) {
			if (!used[i]) {
				dfsBridge(i, -1);
			}
		}
		Collections.sort(bridges);
		Arrays.fill(used, false);
		cmpId = new int[verticesCount];
		cmpSize = new int[verticesCount];
		cmpEdges = new int[verticesCount];
		for (int i = 0, j = 0; i < verticesCount; i++) {
			if (!used[i]) {
				dfsMark(i, j++);
			}
		}
		for (int u = 0; u < verticesCount; u++) {
			for (int id = firstEdge[u]; id != -1; id = nextEdge[id]) {
				int v = goesTo[id];
				if (u < v && cmpId[u] == cmpId[v]) {
					++cmpEdges[cmpId[u]];
				}
			}
		}
		Arrays.fill(tin, Integer.MAX_VALUE);
		Arrays.fill(fup, Integer.MIN_VALUE);
		for (int i = 0; i < verticesCount; i++) {
			int id = cmpId[i];
			tin[id] = Math.min(tin[id], i);
			fup[id] = Math.max(fup[id], i);
		}
		ArrayList<Restriction> restrictions = new ArrayList<>();
		for (int i = 0; i < verticesCount; i++) {
			if (cmpSize[i] > 0) {
				if (cmpEdges[i] >= cmpSize[i]) {
					restrictions.add(new Restriction(tin[i], fup[i]));
				}
			}
		}
		Collections.sort(restrictions);
		for (int i = restrictions.size() - 2; i >= 0; i--) {
			restrictions.get(i).minAfter = Math.min(restrictions.get(i).minAfter, restrictions.get(i + 1).minAfter);
		}
		int cursor = 0;
		int[] rightBorder = new int[verticesCount];
		for (int l = 0; l < verticesCount; l++) {
			while (cursor < restrictions.size() && restrictions.get(cursor).greater < l) {
				++cursor;
			}
			rightBorder[l] = (cursor == restrictions.size() ? verticesCount : restrictions.get(cursor).minAfter);
		}
		long[] sums = new long[verticesCount];
		for (int i = 0; i < verticesCount; i++) {
			sums[i] = (rightBorder[i] - i);
			if (i > 0)
				sums[i] += sums[i - 1];
		}
		int queriesCount = nextInt();
		for (int q = 0; q < queriesCount; q++) {
			int l = nextInt() - 1;
			int r = nextInt() - 1;
			int m = findBreakPoint(rightBorder, l, r);
			long result = getSum(sums, l, m);
			if (m + 1 <= r) {
				result += getSumSimple(m + 1, r);
			}
			out.println(result);
		}
	}

	private int findBreakPoint(int[] rightBorder, int l, int r) {
		--l;
		++r;

		int threshold = r;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (rightBorder[m] <= threshold) {
				l = m;
			} else {
				r = m;
			}
		}
		return l;
	}

	private long getSumSimple(int l, int r) {
		long cnt = (r - l + 1);
		return cnt * (cnt + 1) / 2;
	}

	private long getSum(long[] sums, int l, int r) {
		if (r < 0)
			return 0;
		return sums[r] - (l == 0 ? 0 : sums[l - 1]);
	}

	public static void main(String[] args) {
		new Thread(null, new C(), "C", (1L << 26)).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null)
				return null;

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}