Сonnect

아직 제출이 없습니다시간 제한2.5초메모리 제한1024 MB

문제

Because of all the travelling around the country for IATI 2022, the tour guide company of Kyusho was once again overwhelmed with questions. The region, for which his company is responsible, consists of NN cities, numbered from 11 to NN. Between them, there are MM direct roads, numbered from 11 to MM, each connecting a pair of different cities. There may be more than one direct road in a given direction between two cities.

The dispatch department frequently receives questions from the bus drivers which are of the following type: "Can you always go from city AA to city BB and then go back to city AA even if one of the roads is closed?".

Kyusho knows that you’re an experienced programmer so he asks you to write a program connect that answers the incoming questions of the described type.

입력

The first line of the standard input contains two positive integers: NN – the number of cities and MM – the number of direct roads in the region.

Each of the next MM lines contains two positive integers AA and BB, which specify that there is a direct road from city AA to city BB.

The next line contains the positive integer QQ – the number of questions. Each of the following QQ lines contains two positive integers AA and BB, describing a question from a driver, asking about cities AA and BB.

Note that sometimes the questions are so many that Kyusho thinks it‘s best to get the answers for each unordered pair of cities (A,B)(A, B). For convenience, when Q=0Q = 0 it will imply that we are in that case. Then the questions (1,1)(1,1); (1,2)(1,2); (1,3)(1,3); \dots; (1,N)(1,N); (2,2)(2,2); (2,3)(2 ,3); \dots; (2,N)(2,N); (3,3)(3,3); \dots; (3,N)(3,N); \dots; (N,N)(N,N); have to be answered in that order.

출력

For each question we will assign a number in the following way:

  • 00 → Even without closing one of the roads, there is no route between the two cities in the question in at least one of the two directions.
  • M+1M+1 → No matter which road is closed, there is always a route between the two cities in both directions.
  • Number between 11 and MM → the number of the road, whose closure will lead to no route in one of the two directions. If there is more than one possible road to close, the answer has to be the one with the lowest number.

Let the resulting numbers for the questions are: s_1,s_2,s_3,,s_Ks\_1, s\_2, s\_3, \dots , s\_K, where K=QK = Q if Q0Q \ne 0 and K=(N×(N+1))/2K = (N \times (N + 1)) / 2 if Q=0Q = 0. Then on a single line of the standard output print the remainder of the number P=s_1×BK1+s2×BK2+s_3×BK3++s_K×B0P = s\_1 \times B^{K-1} + s2 \times B^{K-2} + s\_3 \times B^{K-3} + \cdots + s\_K \times B^0 modulo 109+710^9 + 7 where B=2×105B = 2 \times 10^5.

제한

  • 2N20002 ≤ N ≤ 2000
  • 1A,BN1 ≤ A, B ≤ N
  • 1M1051 ≤ M ≤ 10^5
  • 0Q1050 ≤ Q ≤ 10^5