The first line of the input is an integer $t$, denoting the number of test cases.
For each test case, there is two space-separated integers $n$ ($1 \le n \le 500~000$) and $q$ ($1 \le q \le 500~000$) in the first line, meaning the total number of levels and the number of queries.
Then follows $n$ lines, each containing integers $r_i$, $s_i$, $x_i$, $a_i$ ($1 \le r_i \le s_i \le 10^9$, $1 \le x_i \le i$, $0 \le a_i \le 10^9$), space separated. Note that $p_i$ is given in the form of a fraction $\frac{r_i}{s_i}$.
The next $q$ lines are $q$ queries. Each of these queries are two space-separated integers $l$ and $r$ ($1 \le l < r \le n + 1$).
The sum of $n$ and sum of $q$ from all $t$ test cases both does not exceed $10^6$.