A grid of size (2n+1)×(2n+1) is filled as follows. Write 1 in the center square, write 2 in the square to its right, then keep writing the following numbers along a counterclockwise spiral.
A square is addressed by integer coordinates (x,y). The center square is (0,0), x grows to the right, and y grows upward, so every square of the grid satisfies −n≤x≤n and −n≤y≤n. The grid for n=2 looks like this.
You are given q rectangular regions. For each region, compute the sum of the numbers inside it modulo 109+7.