{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eCuber 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.\u003cbr\u003e\u003cbr\u003eThis game follows a traditional Kejin rule of \"when you are level $i$, you have to pay $a_i$ RMB to get to level $i+1$\". Cuber QQ now changed it a little bit: \"when you are level $i$, you pay $a_i$ RMB, are you get to level $i+1$ with probability $p_i$; otherwise you will turn into level $x_i$ ($x_i \\le i$)\".\u003cbr\u003e\u003cbr\u003eCuber QQ still needs to know how much money expected the Kejin players needs to ``ke\u0027\u0027 so that they can upgrade from level $l$ to level $r$, because you worry if this is too high, these players might just quit and never return again.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input is an integer $t$, denoting the number of test cases.\u003cbr\u003e\u003cbr\u003eFor 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.\u003cbr\u003e\u003cbr\u003eThen 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}$.\u003cbr\u003e\u003cbr\u003eThe next $q$ lines are $q$ queries. Each of these queries are two space-separated integers $l$ and $r$ ($1 \\le l \u0026lt; r \\le n + 1$).\u003cbr\u003e\u003cbr\u003eThe sum of $n$ and sum of $q$ from all $t$ test cases both does not exceed $10^6$."}},{"title":"Output","value":{"format":"HTML","content":"For each query, output answer in the fraction form modulo $10^9+7$, that is, if the answer is $\\frac{P}{Q}$, you should output $P \\cdot Q^{-1}$ modulo $10^9+7$, where $Q^{-1}$ denotes the multiplicative inverse of $Q$ modulo $10^9+7$.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n3 2\r\n1 1 1 2\r\n1 2 1 3\r\n1 3 3 4\r\n1 4\r\n3 4\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e22\r\n12\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eHuge IO (Over 40MB)! IO optimization is preferred.\u003cbr\u003e"}}]}