{"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\"\u003eThere are $n$ houses on the ground, labeled by $1$ to $n$. The $i$-th house is located at $(i,y_i)$, and there is a spy transmitter with energy $w_i$ inside the $i$-th house.\u003cbr\u003eLittle Q has a rectangle radar scanner, which can find all the transmitters within the range $[xl,xr]\\times[yl,yr]$. That means a transmitter located at $(x,y)$ can be found if $xl\\leq x\\leq xr$ and $yl\\leq y\\leq yr$.\u003cbr\u003eYour task is to achieve the scanner efficiently.\u003cbr\u003eGiven $m$ queries $xl_i,xr_i,yl_i,yr_i$, for each query, please find all the transmitters within the range, then report the product of their energy and the maximum/minimum energy among them.\u003cbr\u003eTo reduce the large input, we will use the following generator. The numbers $a_0,b_0,c_0,d_0,p,q,r$ and $MOD$ are given initially. The values $a_i,b_i,c_i,d_i,xl_i,xr_i,yl_i,yr_i$ are then produced as follows :\u003cbr\u003e\\begin{eqnarray*}\u003cbr\u003ea_i\u0026amp;\u003d\u0026amp;(p\\times a_{i-1}+q\\times b_{i-1}+r)\\bmod MOD\\\\\u003cbr\u003eb_i\u0026amp;\u003d\u0026amp;(p\\times b_{i-1}+q\\times a_{i-1}+r)\\bmod MOD\\\\\u003cbr\u003ec_i\u0026amp;\u003d\u0026amp;(p\\times c_{i-1}+q\\times d_{i-1}+r)\\bmod MOD\\\\\u003cbr\u003ed_i\u0026amp;\u003d\u0026amp;(p\\times d_{i-1}+q\\times c_{i-1}+r)\\bmod MOD\\\\\u003cbr\u003exl_i\u0026amp;\u003d\u0026amp;\\min(a_i\\bmod n,b_i\\bmod n)+1\\\\\u003cbr\u003exr_i\u0026amp;\u003d\u0026amp;\\max(a_i\\bmod n,b_i\\bmod n)+1\\\\\u003cbr\u003eyl_i\u0026amp;\u003d\u0026amp;\\min(c_i\\bmod n,d_i\\bmod n)+1\\\\\u003cbr\u003eyr_i\u0026amp;\u003d\u0026amp;\\max(c_i\\bmod n,d_i\\bmod n)+1\u003cbr\u003e\\end{eqnarray*}\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer $T(1\\leq T\\leq3)$, denoting the number of test cases.\u003cbr\u003eIn each test case, there is an integer $n(1\\leq n\\leq 100000)$ in the first line, denoting the number of houses.\u003cbr\u003eIn the next $n$ lines, each line contains $2$ integers $y_i,w_i(1\\leq y_i\\leq n,1\\leq w_i\\leq 10^9)$, describing a house.\u003cbr\u003eThen in the next line, there are $10$ integers $m,a_0,b_0,c_0,d_0,p,q,r,MOD,k$, describing the queries. It is guaranteed that $1\\leq m\\leq 10^6$ and $5\\leq a_0,b_0,c_0,d_0,p,q,r,MOD,k\\leq 10^9$.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"Since the output file may be very large, let\u0027s denote $prod_i$ as the product of of the $i$-th query, $max_i$ as the maximum energy of the $i$-th query, and denote $min_i$ as the minimum energy of the $i$-th query. Note that when there are no avaliable transmitters, then $prod_i\u003dmax_i\u003dmin_i\u003d0$.\u003cbr\u003eFor each test case, you need to print a single line containing an integer $answer$, where :\u003cbr\u003e\\begin{eqnarray*}\u003cbr\u003eanswer\u0026amp;\u003d\u0026amp;\\sum_{i\u003d1}^{m} ((prod_i\\bmod k)\\oplus max_i\\oplus min_i)\u003cbr\u003e\\end{eqnarray*}\u003cbr\u003eNote that ``$\\oplus$\u0027\u0027 denotes binary XOR operation.\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\t\t\t\t\t\t\t\t\t\r\n5\t\t\t\t\t\t\t\t\t\r\n2 6\t\t\t\t\t\t\t\t\r\n1 8\t\t\t\t\t\t\t\t\r\n5 2\t\t\t\t\t\t\t\t\r\n4 9\t\t\t\t\t\t\t\t\r\n2 4\t\t\t\t\t\t\t\t\r\n3 5 6 7 8 9 8 7 998244353 10007\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e68\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}