You got a treasure map that marks $$$n$$$ pirate chests buried in the ground, labeled by $$$1,2,\dots,n$$$. The $$$i$$$-th chest is located at point $$$(i,p_i)$$$ on the plane. When you open the $$$i$$$-th pirate chest, you will get $$$v_i$$$ coins.
You will start at $$$(0,0)$$$, and every time you can choose to move from $$$(x,y)$$$ to $$$(x+1,y)$$$ or $$$(x,y+1)$$$. You can dig up a pirate chest and take all the coins it contains when you are right above it.
Unfortunately, there is a dangerous trap area that is not marked! Through much research, you know that this is a rectangular area with sides parallel to the coordinate axes, and that it can only be one of $$$m$$$ possible areas. Please write a program to calculate how many coins you can take by following the optimal route for each possible case.
Assume that the real trap area is the $$$i$$$-th rectangle $$$[x_1,x_2]\times [y_1,y_2]$$$, then a position $$$(x,y)$$$ is considered to be dangerous if and only if $$$x_1\leq x\leq x_2$$$ and $$$y_1\leq y\leq y_2$$$. You should never pass through any dangerous position.
The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 100$$$), the number of test cases. For each test case:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n,m\leq 300\,000$$$), denoting the number of pirate chests and the number of possible traps.
Each of the following $$$n$$$ lines contains two integers $$$p_i$$$ and $$$v_i$$$ ($$$1\leq p_i\leq n$$$, $$$1\leq v_i\leq 10^9$$$), describing each pirate chest. It is guaranteed that the values of all $$$p_i$$$ are pairwise distinct.
Each of the following $$$m$$$ lines contains four integers $$$x_1,y_1,x_2$$$ and $$$y_2$$$ ($$$1\leq x_1\leq x_2\leq n$$$, $$$1\leq y_1\leq y_2\leq n$$$), describing each possible rectangular trap area.
It is guaranteed that the sum of all $$$n$$$ is at most $$$1\,500\,000$$$, and the sum of all $$$m$$$ is at most $$$1\,500\,000$$$.
For each test case, output $$$m$$$ lines, the $$$i$$$-th ($$$1\leq i\leq m$$$) of which containing an integer, denoting the maximum number of coins that you can take when the dangerous trap area is the $$$i$$$-th rectangle.
13 52 43 31 51 1 1 11 1 1 32 1 3 31 1 3 21 1 3 3
7 5 4 3 0
| Name |
|---|


