#include <iostream>
//#include <cstdio>
using namespace std;
const int N = 1010;
int n, m, q;
int s[N][N];//二维数组
int main()
{
ios::sync_with_stdio(0);
cin >> n >> m >> q;
for (int i = 1; i <= n; i ++ ) //输入矩阵
{
for (int j = 1; j <= m; j ++ )
{
cin >> s[i][j];
}
}
for (int i = 1; i <= n; i ++ )//求和后矩阵
{
for (int j = 1; j <= m; j ++ )
{
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
//二维前缀和预处理公式
}
}
while (q -- )
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] << endl;
//以(x1, y1)为左上角,(x2, y2)为右下角的子矩阵的和//减去多余部分
}
return 0;
}
scanf / printf 750ms
cin / cout 3000ms
cin / cout + ios::sync_with_stdio(0); 1500ms