Edge Destruction

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 MB

Problem

Seunghyun 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 VV vertices and EE edges. The vertices are numbered 1,2,,V1, 2, \dots, V, the edges are numbered 1,2,,E1, 2, \dots, 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,,rl, l+1, \dots, 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 ll through rr 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.

Input

The first line contains the number of vertices VV and the number of edges EE, separated by a space.

Each of the next EE lines describes one edge. The ii-th of those lines contains two integers uiu_i and viv_i separated by a space, meaning that edge ii joins vertex uiu_i and vertex viv_i. The graph is undirected and at most one edge joins any pair of vertices.

The next line contains the number of destroy calls QQ. Each of the next QQ lines contains the arguments ll and rr of one call, separated by a space.

5V7005 \le V \le 700, 1E1234561 \le E \le 123456, 1Q500001 \le Q \le 50000, 1ui,viV1 \le u_i, v_i \le V, uiviu_i \ne v_i, 1lrE1 \le l \le r \le E

Output

For each destroy call, print on its own line the number of components of the graph with edges ll through rr 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 ll through rr removed.

Note

The graph in the first example is the graph of [Figure 3].