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 java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ogiekako
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		MyScanner in = new MyScanner(inputStream);
		MyPrintWriter out = new MyPrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, MyScanner in, MyPrintWriter out) {
        int n = in.nextInt(), m = in.nextInt();
        Edge[] es = new Edge[m];
        for(int i=0;i<m;i++){
            es[i] = new Edge(in.nextInt()-1,in.nextInt()-1);
        }
        int[][] tree = new int[m+1][];
        int[][] revTree = new int[m+1][];
        UnionFind uf = new UnionFind(n);
        tree[0] = uf.tree.clone();
        for(int i=0;i<m;i++){
            uf.union(es[i].x,es[i].y);
            tree[i+1] = uf.tree.clone();
        }
        uf = new UnionFind(n);
        revTree[m] = uf.tree.clone();
        for(int i=m-1;i>=0;i--){
            uf.union(es[i].x,es[i].y);
            revTree[i] = uf.tree.clone();
        }
        int k = in.nextInt();
        for (int i = 0; i < k; i++){
            int s=in.nextInt()-1, t=in.nextInt();
            uf = new UnionFind(tree[s].clone());
            UnionFind uf2 = new UnionFind(revTree[t]);
            for(int j=0;j<n;j++)uf.union(j,uf2.root(j));
            int res = 0;
            for(int j=0;j<n;j++)if(uf.root(j) == j)res++;
            out.println(res);
        }
    }
    class Edge{
        int x,y;
        public Edge(int x, int y) {
            this.x=x;this.y=y;
        }
    }
}

class MyScanner {
    private final InputStream in;

    public MyScanner(InputStream in) {
        this.in = in;
    }

    int bufLen;
    int bufPtr;
    byte[] buf = new byte[1024];

    public int read() {
        if (bufLen == -1)
            throw new InputMismatchException();
        if (bufPtr >= bufLen) {
            bufPtr = 0;
            try {
                bufLen = in.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (bufLen <= 0)
                return -1;
        }
        return buf[bufPtr++];
    }

    public int nextInt() {
        int c = read();
        if (c == -1) throw new NoSuchElementException();
        while (c != '-' && (c < '0' || '9' < c)) {
            c = read();
            if (c == -1) throw new NoSuchElementException();
        }
        if (c == '-') return -nextInt();
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while ('0' <= c && c <= '9');
        return res;
    }


    }

class MyPrintWriter {
    PrintWriter out;

    public MyPrintWriter(OutputStream outputStream) {
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public MyPrintWriter(Writer writer) {
        out = new PrintWriter(writer);
    }

    public void println(Object... os) {
        for (int i = 0; i < os.length - 1; i++) {
            out.print(os[i]);
            out.print(' ');
        }
        out.println(os[os.length - 1]);
    }

    public void close() {
        out.close();
    }

    }

class UnionFind {
    public final int[] tree;

    public UnionFind(int n) {
        this.tree = new int[n];
        Arrays.fill(tree, -1);
    }

    public UnionFind(int[] tree) {
        if(tree == null)throw new NullPointerException();
        this.tree = tree;
    }

    /**
     * @return true if x and y are already in a same component.
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return true;
        if (tree[x] > tree[y]) {
            tree[y] += tree[x];
            tree[x] = y;
        } else {
            tree[x] += tree[y];
            tree[y] = x;
        }
        return false;
    }

    public int root(int x) {
        return tree[x] < 0 ? x : (tree[x] = root(tree[x]));
    }

    }