#include <stdio.h> #define ll long long int main() { int n, m, q; if (scanf("%d %d %d", &n, &m, &q) != EOF) { ll matrix[n + 1][m + 1], matrixsum[n + 1][m + 1]; for(int i = 0; i < n; i++) { matrixsum[0][i] = 0; matrixsum[i][0] = 0; } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(scanf("%lld", &matrix[i][j]) != EOF) { matrixsum[i][j] = matrixsum[i - 1][j] + matrixsum[i][j - 1] - matrixsum[i - 1][j - 1] + matrix[i][j]; } else printf("error2\n"); } } while(q--) { int x1, y1, x2, y2; if(scanf("%d %d %d %d", &x1, &y1, &x2, &y2) != EOF) { printf("%lld\n", matrixsum[x2][y2] - matrixsum[x1 -1][y2] - matrixsum[x2][y1 - 1] + matrixsum[x1 - 1][y1 - 1]); } else printf("error3\n"); } } else printf("error1\n"); return 0; }