Given a 2D array Arr, find the sum of elements in a given range.
There will be multiple queries in this question.
Definition of the sum of elements in a given range X1, Y1, X2, Y2:
Sum = Σ(Arr[i][j]), X1 ≤ i ≤ X2, Y1 ≤ j ≤ Y2
This problem is an extended version of homework 12022 - prefix sum. You will need to use similar techniques to solve this problem.
The first line contains 2 integers N, M that specify the matrix size.
For the next N lines, each of them contains M integers. The j-th integer in the i-th of these lines is Arr[i][j].
Then the next line (N+2-th line) contains an integer Q, meaning there will be Q queries.
Then for the next Q lines (each of them forms a query), each contains 4 integers X1, Y1, X2, Y2, indicating the range of the sub-matrix.
1 ≤ X1 ≤ X2 ≤ N, 1 ≤ Y1 ≤ Y2 ≤ M.
It is guaranteed that every element is less than 50 (0 ≤ Arr[i][j] ≤ 49).
For each query, output one line containing an integer representing the sum of elements of the submatrix.