Graph Search 2

After each of q planned roads is built, print each city's shortest-path distance to city 1, where it takes one edge.

Medium5BFSGraphInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

King zych of Namgyu announced a road construction plan. The plan lists roads between pairs of cities in order, and because building one road is a large job, the crew builds them one at a time in the listed order.

To prepare the next plan, zych measures the shortest route from every city to the capital after each road is built. The value of city ii is the minimum number of roads you pass when you travel from city ii to the capital. The value of the capital itself is 00, and if no sequence of roads reaches the capital, the value is 1-1.

You are given the initial cities and roads together with the construction plan. Write a program that prints the value of city 11 through city nn after each road is built.

Input

The first line contains the number of cities nn and the number of roads that already exist mm. (2n10002 \le n \le 1000, 1m1000001 \le m \le 100000)

Each of the next mm lines contains the numbers of the two cities that a road connects.

The next line contains the number of roads in the construction plan qq. (1q5001 \le q \le 500)

Each of the following qq lines contains two integers ii and jj, meaning that a new road between city ii and city jj is built. (1i,jn1 \le i, j \le n)

Every road is bidirectional. Several roads may connect the same pair of cities, and ii may equal jj. The capital is city 11.

Output

Print qq lines. On line tt, print the value of city 11 through city nn after the first tt roads of the plan are built, separated by single spaces.