Paint by Letters

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Bessie has recently received a painting set. The canvas can be represented as an N×MN \times M rectangle of cells where the rows are labeled 1N1\ldots N from top to bottom and the columns are labeled 1M1\ldots M from left to right (1N,M10001\le N,M\le 1000). Once painted, the color of a cell can be represented by an uppercase letter from 'A' to 'Z.' Initially, all cells are uncolored, and a cell cannot be painted more than once.

Bessie has specified the color that she desires for each cell. She can paint a set of cells with a single color in one stroke if the set forms a connected component, meaning that any cell in the set can reach any other via a sequence of adjacent cells. Two cells are considered to be adjacent if they share an edge.

For example, the 3×33\times 3 canvas

AAB
BBA
BBB

can be colored in four strokes as follows:

...    ..B    AAB    AAB    AAB
... -> ... -> ... -> BB. -> BBA
...    ...    ...    BBB    BBB

It is not possible to produce the end result using less than four strokes.

Being an avant-garde artist, Bessie will end up painting only a subrectangle of the canvas. Currently, she is considering QQ candidates (1Q10001\le Q\le 1000), each of which can be represented by four integers x_1x\_1, y_1y\_1, x_2x\_2, and y_2.y\_2. This means that the subrectangle consists of all cells with row in the range x_1x\_1 to x_2x\_2 inclusive and column in the range y_1y\_1 to y_2y\_2 inclusive.

For each candidate subrectangle, what is the minimum number of strokes needed to paint each cell in the subrectangle with its desired color while leaving all cells outside the subrectangle uncolored? Note that Bessie does not actually do any painting during this process, so the answers for each candidate are independent.

입력

The first line contains NN, MM, and QQ.

The next NN lines each contain a string of MM uppercase characters representing the desired colors for each row of the canvas.

The next QQ lines each contain four space-separated integers x_1,y_1,x_2,y_2x\_1,y\_1,x\_2,y\_2 representing a candidate subrectangle (1x_1x_2N1\le x\_1\le x\_2\le N, 1y_1y_2M1\le y\_1\le y\_2\le M).

출력

For each of the QQ candidates, output the answer on a new line.