Big Table

Each row of a huge table repeats a short digit period; answer rectangle-sum queries without materializing the table.

Medium6Prefix sumMathImplementationArrayNo attempts yetTime limit4sMemory limit128 MB

Problem

Mirko and Slavko are always playing some game. They got bored of every existing one, so they decided to invent their own. Mirko imagines a large table of single-digit numbers and writes it down, and Slavko has to answer questions of the form "What is the sum of the numbers in this rectangle?" as fast as he can.

So that Mirko does not have to write out every number of the imagined table, the two agreed on the following. Each row of the table is built by concatenating the row's base period many times and then discarding elements from the end until the row is exactly as wide as the table.

Input

The first line contains RR and SS (1R,S1000001 \le R, S \le 100\,000), the number of rows and the number of columns of the table.

The next RR lines contain the base periods of the rows, from the top row down. Each period consists of at most min(S,100)\min(S, 100) digits from 0 to 9, written one after another without spaces.

The next line contains QQ (1Q1000001 \le Q \le 100\,000), the number of questions Slavko has to answer.

Each of the following QQ lines contains four integers r1,s1,r2,s2r_1, s_1, r_2, s_2 (1r1r2R1 \le r_1 \le r_2 \le R and 1s1s2S1 \le s_1 \le s_2 \le S) that describe a rectangle in which Slavko has to find the sum of the numbers. r1r_1 and s1s_1 give the top-left cell of the rectangle (row r1r_1, column s1s_1), and r2r_2 and s2s_2 give the bottom-right cell. Rows are numbered 1 to RR from top to bottom, and columns are numbered 1 to SS from left to right.

Output

Print QQ lines with Slavko's answers in the order of the questions, exactly one number per line.

Hint

The periods in the first sample input describe this table:

1111111111
0404040404
1231231231
9898989898

Slavko has to answer a single question, which asks for the sum of all numbers in the table. That sum is 134.