#include <iostream>
using namespace std;
const int MAX_SIZE = 100;
int main() {
int n, m, nr_area, mt[MAX_SIZE + 1][MAX_SIZE + 1];
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> mt[i][j];
}
}
cin >> nr_area;
int i1, j1, i2, j2;
// we go through and read each area
for (int area = 1; area <= nr_area; ++area) {
cin >> i1 >> j1 >> i2 >> j2;
int amount = 0;
//we go through the elements of the area and find their sum
for (int i = i1; i <= i2; ++i) {
for (int j = j1; j <= j2; ++j) {
amount += mt[i][j];
}
}
cout << "n";
cout << amount;
amount = 0;
}
return 0;
}