1. #include <iostream>
    2. using namespace std;
    3. const int N = 1010;
    4. int sum[N][N];
    5. int main (){
    6. int a[N][N],n,m,q;
    7. long long sum[N][N];
    8. cin >> n >> m >> q;
    9. // for(int i = 0; i <= n; i++ ) sum[i][0] =0;
    10. // for(int j = 0; j <= m; j++ ) sum[0][j] =0;
    11. for(int i = 1; i <= n; i++ ){
    12. for(int j = 1; j <= m; j++){
    13. cin >> a[i][j];
    14. sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + a[i][j];
    15. }
    16. }
    17. while(q--){
    18. int x1,y1,x2,y2;
    19. cin >> x1 >> y1 >> x2 >> y2;
    20. cout << sum[x2][y2] - sum[x1-1][y2] -sum[x2][y1-1] + sum[x1-1][y1-1] << endl;
    21. }
    22. return 0;
    23. }