#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2100;
const int K = 30;
const int mod = 1e9 + 7;
string s[N];
int used[N][N], b[N][N], d[N][N], su[N][N], sl[N][N], sr[N][N], sd[N][N];
pair <int, int> p[N][N];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m;
void dfs(int vx, int vy, int px = -2, int py = -2){
    p[vx][vy] = {px, py};
    used[vx][vy] = 1;
    for (int i = 0; i < 4; i++){
        int nvx = vx + dx[i];
        int nvy = vy + dy[i];
        if (nvx < n && nvx >= 0 && nvy < m && nvy >= 0 && !used[nvx][nvy] && s[nvx][nvy] == '1'){
            dfs(nvx, nvy, vx, vy);
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q;
    cin >> n >> m >> q;
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (!used[i][j] && s[i][j] == '1'){
                dfs(i, j);
                b[i][j]++;
            }
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            d[i][j] = (i > 0) * d[i - 1][j] + (j > 0) * d[i][j - 1] - (i > 0 && j > 0) * d[i - 1][j - 1] + b[i][j];
        }
    }
    for (int u = 1; u < n; u++){
        for (int i = 0; i < m; i++){
                            if (i != 0) su[u][i] = su[u][i - 1];
            if (s[u - 1][i] == '1' && s[u][i] == '1'){

                if (p[u][i] == make_pair(u - 1, i)) su[u][i]++;
            }
        }
    }
    for (int dd = 0; dd < n - 1; dd++){
        for (int i = 0; i < m; i++){
                            if (i!= 0) sd[dd][i] = sd[dd][i - 1];
            if (s[dd + 1][i] == '1' && s[dd][i] == '1'){

                if (p[dd][i] == make_pair(dd + 1, i)) sd[dd][i]++;
            }
        }
    }
    for (int l = 1; l < m; l++){
        for (int i = 0; i < n; i++){
            if (i != 0) sl[l][i] = sl[l][i - 1];
            if (s[i][l - 1] == '1' && s[i][l] == '1'){

                if (p[i][l] == make_pair(i, l - 1)) sl[l][i]++;
            }
        }
    }
    for (int r = 0; r < m - 1; r++){
        for (int i = 0; i < n; i++){
                            if (i != 0) sr[r][i] = sr[r][i - 1];
            if (s[i][r + 1] == '1' && s[i][r] == '1'){

                if (p[i][r] == make_pair(i, r + 1)) sr[r][i]++;
            }
        }
    }
    while(q--){
        int l, r, u, dd;
        int ans = 0;
        cin >> u >> l >> dd >> r;
        u--;
        l--;
        dd--;
        r--;
        ans += sr[r][dd] - (u > 0) * sr[r][u - 1];
        ans += sl[l][dd] - (u > 0) * sl[l][u - 1];
        ans += su[u][r] - (l > 0) * su[u][l - 1];
        ans += sd[dd][r] - (l > 0) * sd[dd][l - 1];
        ans += d[dd][r] - (u > 0) * d[u - 1][r] - (l > 0) * d[dd][l - 1] + (l > 0 && u > 0) * d[u - 1][l - 1];
        cout << ans << endl;
    }
}


Measured memory_bytes: 156280