Under construction

Still being built. Things may change

Road Connectivity

Time limit2sMemory limit256 MB

Summary
Each day one of the 10 roads is picked at random and its open or closed state is flipped. For each query [l, r], find the probability the country is connected on some day in that range.
Level

Hard8 of 10

Topics
Probability, Matrix, Bit manipulation, Graph
Solved
No attempts yet

Statement

There are nn cities in the country of Byteland. Every two cities are connected by a bidirectional road. For every road, the passage through it is either permitted (open) or prohibited (closed). On day 00, only mm roads are open.

Every day (starting from day 11), the government of Byteland chooses a road. Each road has the same probability to be chosen. Then, if the passage through the road is permitted, the government closes the road; otherwise, if it is prohibited, the government opens it.

The government of Byteland is very concerned about communication between cities. There are qq periods of days [l,r][l, r] for which the government wants to know the probability that there is a day within the period such that in this day the country is connected. We say that the country is connected if one can travel from any city to any other using one or several permitted roads.

It can be shown that the required probabilities can be expressed as rational numbers of the form P/QP/Q where PP and QQ are coprime and Q≢0(mod109+7)Q \not\equiv 0 \pmod{10^9 + 7}. Calculate them and print in the form P⋅Q−1(mod109+7)P \cdot Q^{-1} \pmod{10^9 + 7}.

Input

The first line contains two integers nn and mm (2≤n≤52 \le n \le 5, 0≤m≤n⋅(n−1)20 \le m \le \frac{n \cdot (n - 1)}{2}), the number of cities in Byteland and the number of roads for which passage is permitted on day 00.

Each of the following mm lines contains two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i), the cities which are connected by the ii-th permitted road. It is guaranteed that all permitted roads are pairwise different.

The next line contains one integer qq (1≤q≤10001 \le q \le 1000), the number of queries.

Each of the following qq lines contains two integers ll and rr (0≤l≤r≤10150 \le l \le r \le 10^{15}), the periods of days about which the government is concerned.

Output

Output qq lines, one integer per line. The ii-th line must contain the answer for the ii-th query in the form P⋅Q−1(mod109+7)P \cdot Q^{-1} \pmod{10^9 + 7}, where P/QP/Q is the corresponding probability.

Hint

In the first example, the government has not chosen any road in the first query, and the country is not connected from the beginning, so the probability is 00. In the 2nd to 9th queries, the probabilities are equal to 2/32/3, 2/32/3, 8/98/9, 8/98/9, 2/32/3, 2/92/9, 20/2720/27, and 20/8120/81, respectively.

Examples2

  1. Example 1

    Input
    3 1
    1 2
    9
    0 0
    0 1
    0 2
    0 3
    0 4
    1 1
    2 2
    3 3
    4 4
    
    Expected output
    0
    666666672
    666666672
    888888896
    888888896
    666666672
    222222224
    407407411
    469135806
    
  2. Example 2

    Input
    2 1
    1 2
    5
    0 0
    0 1
    1 1
    1 1000
    0 1000
    
    Expected output
    1
    1
    0
    1
    1