Sum in a matrix#684

Sum in a matrix

2 seconds
128 megabytes
Very easy

Given an integer matrix a_{ij} of size n \times m, where 1 \leq i \leq n, 1 \leq j \leq m, compute the sum for the given indices l_x, l_y, r_x, r_y:

\sum_{i=l_x}^{r_x} \sum_{j=l_y}^{r_y} a_{ij}.

Input

The first line contains two integers and m~(1 \le n, m \le 1000) — the dimensions of the matrix.

The next lines contain integers each, representing the elements of the matrix a_{ij}~(1 \le a_{ij} \le 1000).

The following line contains an integer q~(1 \le q \le 10^6) — the number of queries.

Each of the next lines contains four integers l_{x_i}, l_{y_i}, r_{x_i}, r_{y_i}~(1 \le l_{x_i} \le r_{x_i} \le n, 1 \le l_{y_i} \le r_{y_i} \le m) — the parameters of the query.

Output

Print integers, one per line — the answers to the queries.

Examples

Example 1

Loading
Loading