There 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.
Little 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$.
Your task is to achieve the scanner efficiently.
Given $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.
To 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 :
\begin{eqnarray*}
a_i&=&(p\times a_{i-1}+q\times b_{i-1}+r)\bmod MOD\\
b_i&=&(p\times b_{i-1}+q\times a_{i-1}+r)\bmod MOD\\
c_i&=&(p\times c_{i-1}+q\times d_{i-1}+r)\bmod MOD\\
d_i&=&(p\times d_{i-1}+q\times c_{i-1}+r)\bmod MOD\\
xl_i&=&\min(a_i\bmod n,b_i\bmod n)+1\\
xr_i&=&\max(a_i\bmod n,b_i\bmod n)+1\\
yl_i&=&\min(c_i\bmod n,d_i\bmod n)+1\\
yr_i&=&\max(c_i\bmod n,d_i\bmod n)+1
\end{eqnarray*}