Count the connected components left after deleting edges l through r for each of Q independent queries.
Hard8GraphUnion-findDivide and conquerNo attempts yetTime limit3sMemory limit128 MBSeunghyun studies graph theory to prepare for the national informatics olympiad. Depth first search (DFS) and breadth first search (BFS) have his full attention right now, and he is working on a problem that counts the components of an undirected graph with V vertices and E edges. The vertices are numbered 1,2,…,V, the edges are numbered 1,2,…,E, and at most one edge joins any pair of vertices.
When an undirected graph splits into groups that no edge connects, each subset of mutually connected vertices is a component. In [Figure 1] below, {1, 2, 5, 8}, {3} and {4, 6, 7} are the three components. The whole graph can also be a single component, as in [Figure 2].

Seunghyun wrote a correct DFS solution the moment he read the problem and still scored 0. His teacher saw the code, said "you used a recursive function", and refused to grade it at all. Angry, Seunghyun started calling destroy(l, r), which destroys edges l,l+1,…,r at once. He picked consecutive numbers because they are easier to destroy that way.

[Figure 3] The red number written on an edge is the number of that edge. Seunghyun called destroy(3, 5), so edges 3, 4 and 5 are gone.
You can count components without recursion, so you plan to tease him: count the components of the damaged graph, then call recover(l, r) to put edges l through r back.

[Figure 4] You counted 2 components in the damaged graph and then called recover(3, 5) to restore the edges.
Seunghyun keeps calling destroy, and answering each call by hand has worn you out. Write a program that does the work for you.
The first line contains the number of vertices V and the number of edges E, separated by a space.
Each of the next E lines describes one edge. The i-th of those lines contains two integers ui and vi separated by a space, meaning that edge i joins vertex ui and vertex vi. The graph is undirected and at most one edge joins any pair of vertices.
The next line contains the number of destroy calls Q. Each of the next Q lines contains the arguments l and r of one call, separated by a space.
5≤V≤700, 1≤E≤123456, 1≤Q≤50000, 1≤ui,vi≤V, ui=vi, 1≤l≤r≤E
For each destroy call, print on its own line the number of components of the graph with edges l through r destroyed. Print the answers in input order.
Seunghyun is merciful and calls destroy again only after you restore the graph. Every query therefore applies to the original graph with only edges l through r removed.
The graph in the first example is the graph of [Figure 3].