The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates
)
, a maximum brightness c, equal for all stars, and an initial brightness
)
.
Over time the stars twinkle. At moment 0 the i-th star has brightness

. Let at moment t a star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if

, and 0 otherwise.
You want to look at the sky q times. In the i-th time you will look at the moment

and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates
)
and the upper right —
)
. For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it.