J. Sunlight Field
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have $$$S$$$ solar panels on an $$$n\times n$$$ surface. Each solar panel has a desired quantity of sunlight it needs to receive.

There are currently no clouds above the solar panels surface, but you just received the cloud satellite image for the day, a $$$N\times N$$$ image. The clouds are described as rectilinear non-intersecting polygons whose edges are parallel with the coordinate axis.

The wind is constantly blowing in the $$$(-1,-1)$$$ direction. At each second, the wind pushes the clouds in the said direction.

After each second, if there are no clouds above a solar panel, the amount of sunlight that solar panel receives increments by one, otherwise the quantity stays the same. This repeats forever.

Calculate for each solar panel how many seconds you need to wait to reach the needed quantity of sunlight.

Input

The first line has the size of the surface $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5$$$), the size of the satellite image $$$N$$$ $$$(n \lt N \leq 10^9)$$$ and the number of solar panels $$$S$$$ $$$(1 \leq S \leq 10^5)$$$.

Then $$$S$$$ lines follow, each with the $$$x$$$ and $$$y$$$ of the coordinate of a solar panel $$$(1 \leq x,y \leq 2 \cdot 10^5)$$$ and the needed amount of sunlight $$$q$$$ $$$(1 \leq q \leq 10^9)$$$. The coordinate $$$(x,y)$$$ describes the coordinate of the right uppermost corner of the square the solar panel occupies.

The next line has the number of clouds $$$M$$$ ($$$0 \leq M \leq \lfloor \frac{10^5}{4} \rfloor$$$).

Then for each cloud, we have a line with $$$V$$$, the amount of vertices on the rectilinear polygon ($$$1 \leq V \leq 10^5$$$). Then $$$V$$$ lines follow, each with an $$$x$$$ and $$$y$$$ coordinate describing the vertices of the polygon in clockwise order $$$(n \leq x,y \leq N)$$$.

The sum of $$$V$$$ over all clouds doesn't exceed $$$10^5$$$.

Output

Print a line with how long you need to wait to reach the needed quantity of sunlight, for each solar panel, separated by a space. Print the values in the order given by the input.

Examples
Input
3 7 6
1 3 3
1 2 2
2 3 2
2 2 5
3 2 5
3 1 5
2
6
3 4
3 6
5 6
5 5
4 5
4 4
4
6 5
6 6
7 6
7 5
Output
4 2 4 5 6 5
Input
200000 1000000000 1
200000 200000 1000000000
1
4
200000 200000
200000 1000000000
1000000000 1000000000
1000000000 200000
Output
1999800000