#P7729. [2019年杭电多校]Kejin Player

[2019年杭电多校]Kejin Player

Kejin Player

Problem Description

Cuber QQ always envies those Kejin players, who pay a lot of RMB to get a higher level in the game. So he worked so hard that you are now the game designer of this game. He decided to annoy these Kejin players a little bit, and give them the lesson that RMB does not always work. This game follows a traditional Kejin rule of "when you are level ii, you have to pay aia_i RMB to get to level i+1i+1". Cuber QQ now changed it a little bit: "when you are level ii, you pay aia_i RMB, are you get to level i+1i+1 with probability pip_i; otherwise you will turn into level xix_i (xiix_i \le i)". Cuber QQ still needs to know how much money expected the Kejin players needs to ``ke'' so that they can upgrade from level ll to level rr, because you worry if this is too high, these players might just quit and never return again.

Input

The first line of the input is an integer tt, denoting the number of test cases. For each test case, there is two space-separated integers nn (1n500 0001 \le n \le 500~000) and qq (1q500 0001 \le q \le 500~000) in the first line, meaning the total number of levels and the number of queries. Then follows nn lines, each containing integers rir_i, sis_i, xix_i, aia_i (1risi1091 \le r_i \le s_i \le 10^9, 1xii1 \le x_i \le i, 0ai1090 \le a_i \le 10^9), space separated. Note that pip_i is given in the form of a fraction risi\frac{r_i}{s_i}. The next qq lines are qq queries. Each of these queries are two space-separated integers ll and rr (1l<rn+11 \le l < r \le n + 1). The sum of nn and sum of qq from all tt test cases both does not exceed 10610^6.

Output

For each query, output answer in the fraction form modulo 109+710^9+7, that is, if the answer is PQ\frac{P}{Q}, you should output PQ1P \cdot Q^{-1} modulo 109+710^9+7, where Q1Q^{-1} denotes the multiplicative inverse of QQ modulo 109+710^9+7.

Sample Input

1

3 2

1 1 1 2

1 2 1 3

1 3 3 4

1 4

3 4

Sample Output

22

12

Hint

Huge IO (Over 40MB)! IO optimization is preferred.

Source

2019 Multi-University Training Contest 7