Good Rectangles

Precompute an answer table so each query asks how many all-zero subrectangles fit inside a given rectangle of an n by m binary grid.

Medium7Dynamic programmingPrefix sumMatrixNo attempts yetTime limit4sMemory limit256 MB

Problem

You are given an n×mn \times m grid. Every cell holds 0 or 1. The cell in row ii and column jj is written (i,j)(i, j).

Four integers aa, bb, cc, dd with 1acn1 \le a \le c \le n and 1bdm1 \le b \le d \le m define a rectangle, the set {(x,y):axc, byd}\{(x, y) : a \le x \le c,\ b \le y \le d\} of all cells inside those bounds. A rectangle is good if every cell in it holds 0.

Write a program that answers qq queries. Each query gives one rectangle and asks how many good rectangles are fully contained in it.

Input

The first line contains nn, mm, qq (1n,m501 \le n, m \le 50, 1q3000001 \le q \le 300\,000).

Each of the next nn lines contains a string of length mm made only of the characters 0 and 1, describing one row of the grid. Rows are numbered from 1 top to bottom, and columns are numbered from 1 left to right.

Each of the next qq lines contains one query, given as four integers aa, bb, cc, dd (1acn1 \le a \le c \le n, 1bdm1 \le b \le d \le m) describing a rectangle.

Output

For each query, print the answer on its own line.

Note

The answers to the first sample break down like this.

  • Query 1: five of size 1×11 \times 1, two of size 2×12 \times 1, two of size 1×21 \times 2, one of size 1×31 \times 3
  • Query 2: one of size 1×11 \times 1
  • Query 3: four of size 1×11 \times 1, two of size 2×12 \times 1, one of size 3×13 \times 1