#include "bits/stdc++.h" using namespace std; #define int long long #define endl "\n" #define PII pair<int,int> #define PIII pair<int,PII> const int MOD = 1e9 + 7; const int N = 3e5; void slu() { int n, m, k; cin >> n >> m >> k; vector<vector<PIII>> a(n + 1, vector<PIII >(m + 1, {0, {0, 0}})); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j].first; a[i][j].second.first += a[i][j - 1].second.first + a[i][j].first; a[i][j].second.second += a[i - 1][j].second.second + a[i][j].first; a[i][j].first = a[i][j].second.first + a[i][j].second.second - a[i][j].first + a[i - 1][j - 1].first; } } for (int i = 0; i < k; i++) { int l1, l2, r1, r2; cin >> l1 >> r1 >> l2 >> r2; cout << a[l2][r2].first - a[l2][r1 - 1].first - a[l1 - 1][r2].first + a[l1 - 1][r1 - 1].first << endl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--)slu(); }