Road Connectivity

정점이 5개 이하인 완전 그래프에서 매일 간선 하나가 균등한 확률로 토글될 때, 각 날짜 구간 [l, r] 안에서 그래프가 연결되는 날이 존재할 확률을 구한다.

어려움9확률행렬동적 계획법수학아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

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}. You, as the most cognitive citizen of Byteland, are asked to calculate them and print in the form PQ1(mod109+7)P \cdot Q^{-1} \pmod{10^9 + 7}.

입력

The first line contains two integers nn and mm (2n52 \le n \le 5, 0mn(n1)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 u_iu\_i and v_iv\_i (1u_i,v_in1 \le u\_i, v\_i \le n, u_iv_iu\_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 (1q10001 \le q \le 1000), the number of queries.

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

출력

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

힌트

Let us consider the first example. In the first request, the government has not chosen any road, 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.