#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 999983;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

int tot(vector<vector<int>> a)
{
    int res = 0;
    for (auto vec: a)
        for (auto x: vec) res+=x;
        return res;
}


vector<vector<int>> pref(vector<vector<int>> a)
{
    int n = a.size(); int m = a[0].size();

    vector<vector<int>> res(n+1, vector<int>(m+1));

    for (int i = 1; i<=n; i++)
        for (int j = 1; j<=m; j++)
        {
            res[i][j] = res[i][j-1] + res[i-1][j] - res[i-1][j-1] + a[i-1][j-1];
        }

    return res;
}

int get(vector<vector<int>> &pref, int x1, int x2, int y1, int y2)
{
    return pref[x2+1][y2+1] + pref[x1][y1] - pref[x1][y2+1] - pref[x2+1][y1];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n, m, q;
    cin>>n>>m>>q;

    vector<string> s(n+1);
    for (int i = 0; i<n; i++) cin>>s[i];

    for (int i = 0; i<n; i++) s[i]+='0';
    for (int j = 0; j<m+1; j++) s[n]+='0';

    n++; m++;

    int cnt = 0;
    int edge = 0;

    vector<vector<int>> grid(n, vector<int>(m));

    for (int i = 0; i<n; i++)
        for (int j = 0; j<m; j++) if (s[i][j]=='1') grid[i][j] = 1;

    vector<vector<int>> hor(n, vector<int>(m-1)), ver(n-1, vector<int>(m));


    for (int i = 0; i<n; i++)
        for (int j = 0; j<m-1; j++) if (s[i][j]=='1'&&s[i][j+1]=='1') hor[i][j] = 1;

    for (int i = 0; i<n-1; i++)
        for (int j = 0; j<m; j++) if (s[i][j]=='1' && s[i+1][j]=='1') ver[i][j] = 1;


    auto G = pref(grid);
    auto H = pref(hor);
    auto V = pref(ver);

    int g_tot = tot(grid);
    int h_tot = tot(hor);
    int v_tot = tot(ver);

    /*for (auto vec: grid)
    {
        for (auto x: vec) cout<<x;
        cout<<endl;
    }
    cout<<endl;*/

    /*for (auto vec: ver)
    {
        for (auto x: vec) cout<<x;
        cout<<endl;
    }
    cout<<endl;

    for (auto vec: hor)
    {
        for (auto x: vec) cout<<x;
        cout<<endl;
    }
    cout<<endl;

    for (auto vec: H)
    {
        for (auto x: vec) cout<<x<<' ';
        cout<<endl;
    }
    cout<<endl;*/


    while (q--)
    {
        int x1, x2, y1, y2;
        cin>>x1>>y1>>x2>>y2;
        x1--; x2--; y1--; y2--;

        /*cout<<x1<<' '<<x2<<' '<<y1<<' '<<y2<<endl;

        cout<<get(G, x1, x2, y1, y2) << ' '<< get(V, x1, x2, y1, y2-1) << ' '<< get(H, x1, x2-1, y1, y2)<<endl;*/

        cout<<get(G, x1, x2, y1, y2) -  get(V, x1, x2-1, y1, y2) - get(H, x1, x2, y1, y2-1)<<endl;

    }

}



Measured memory_bytes: 121468