Problem: We already know of the large corporation where Polycarpus works as a system administrator. The computer network there consists of n computers and m cables that connect some pairs of computers. In other words, the computer network can be represented as some non-directed graph with n nodes and m edges. Let's index the computers with integers from 1 to n, let's index the cables with integers from 1 to m.

Polycarpus was given an important task — check the reliability of his company's network. For that Polycarpus decided to carry out a series of k experiments on the computer network, where the i-th experiment goes as follows:

  1. Temporarily disconnect the cables with indexes from li to ri, inclusive (the other cables remain connected). 
  2. Count the number of connected components in the graph that is defining the computer network at that moment. 
  3. Re-connect the disconnected cables with indexes from li to ri (that is, restore the initial network). 



Help Polycarpus carry out all experiments and for each print the number of connected components in the graph that defines the computer network through the given experiment. Isolated vertex should be counted as single component.

Input

The first line contains two space-separated integers n, m (2 ≤ n ≤ 500; 1 ≤ m ≤ 104) — the number of computers and the number of cables, correspondingly.

The following m lines contain the cables' description. The i-th line contains space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the numbers of the computers that are connected by the i-th cable. Note that a pair of computers can be connected by multiple cables.

The next line contains integer k (1 ≤ k ≤ 2·104) — the number of experiments. Next k lines contain the experiments' descriptions. The i-th line contains space-separated integers li, ri (1 ≤ li ≤ ri ≤ m) — the numbers of the cables that Polycarpus disconnects during the i-th experiment. 

Output

Print k numbers, the i-th number represents the number of connected components of the graph that defines the computer network during the i-th experiment. 

Examples

Input

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


Output

4
5
6
3
4
2

Solution (in JAVA):

Solution:
import static java.util.Arrays.*;

import java.util.*;

public class D {

	private final static boolean autoflush = false;

	public D () {
		int N = sc.nextInt();
		int M = sc.nextInt();

		int [][] E = new int [M][];
		for (int i : rep(M))
			E[i] = new int [] { sc.nextInt() - 1, sc.nextInt() - 1 };

		int K = sc.nextInt();
		Integer [] L = new Integer [K], R = new Integer [K];

		for (int i : rep(K)) {
			L[i] = sc.nextInt() - 1;
			R[i] = sc.nextInt() - 1;
		}

		Integer [] JL = si(L);
		Integer [] JR = si(R);
		sort(L); sort(R);

		int [][] CL = new int [K][], CR = new int [K][];

		int [] cc = singletons(N), zz = copyOf(cc, N);
		for (int i : rep(K)) {
			int s = i == 0 ? 0 : L[i-1], t = L[i];
			if (dsu(E, s, t, cc))
				zz = copyOf(cc, N);
			CL[JL[i]] = zz;
		}

		cc = singletons(N); zz = copyOf(cc, N);
		for (int i : sep(K)) {
			int s = R[i]+1, t = i == K-1 ? M : R[i+1]+1;
			if (dsu(E, s, t, cc))
				zz = copyOf(cc, N);
			CR[JR[i]] = zz;
		}

		for (int i : rep(K)) {
			int [] A = CL[i], B = CR[i];
			List<int[]> F = new ArrayList<int[]>();
			for (int j : rep(N))  {
				if (A[j] != j)
					F.add(new int[] { j, A[j] });
				if (B[j] != j)
					F.add(new int[] { j, B[j] });
			}

			for (int j : rep(N))
				cc[j] = j;
			int [][] G = F.toArray(new int [0][]);
			dsu(G, cc);
			int res = nc(cc);
			print(res);
		}
	}

	int [] singletons(int N) {
		int [] res = new int [N];
		for (int i = 0; i < N; ++i)
			res[i] = i;
		return res;
	}

	int [] dsu(int [][] E, int N) {
		int [] res = singletons(N);
		dsu(E, res);
		return res;
	}

	boolean dsu(int [][] E, int [] C) { return dsu(E, 0, E.length, C); }

	boolean dsu(int [][] E, int s, int t, int [] C) {
		boolean res = false;
		for (int i = s; i < t; ++i) {
			int [] e = E[i];
			int u = root(C, e[0]), v = root(C, e[1]);
			if (u != v)
				res = true;
			C[u] = C[v];
		}
		for (int i = 0; i < C.length; ++i)
			root(C, i);
		return res;
	}

	int root (int [] C, int s) {
		int res = s;
		while (C[res] != res)
			res = C[res];
		int v = s;
		while (v != res) {
			v = C[v];
			C[v] = res;
		}
		return C[s] = res;
	}

	int nc (int [] C) {
		int res = 0, N = C.length;
		for (int i = 0; i < N; ++i)
			if (C[i] == i)
				++res;
		return res;
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] sep(int N) { return sep(0, N); }
	private static int [] sep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[T-1-i] = i; return res; }
	private static <T extends Comparable<T>> Integer [] si(final T [] X) {
		return si(X, new Comparator<T> () {
			public int compare (T x, T y) {
				return x.compareTo(y);
			}
		});
	}
	private static <T> Integer [] si(final T [] X, final Comparator<T> C) {
		int N = X.length;
		Integer [] J = new Integer [N];
		for (int i = 0; i < N; ++i)
			J[i] = i;
		sort(J, new Comparator<Integer>() {
			public int compare(Integer i, Integer j) {
				int res = C.compare(X[i], X[j]);
				return res != 0 ? res : i.compareTo(j);
			}
		});
		return J;
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		private String next() {
			newLine();
			return line[index++];
		}
		private int nextInt() {
			return Integer.parseInt(next());
		}
		//////////////////////////////////////////////
		private boolean eol() {
			return index == line.length;
		}
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () {
			this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)));
		}
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) {
		printDelim(" ", o, a);
	}
	private static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() {
		t = millis();
	}
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() {
		return System.currentTimeMillis();
	}
	public static void main (String[] args) {
		new D();
		exit();
	}
}