#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

void show(int h, int w, int g[2010][2010]) {
    rep(i, h) {
        rep(j, w) cout << g[i][j] << ' ';
        cout << endl;
    }
}

int h, w, qq;
char g[2010][2010];

enum Dir {
    L, U, R, D
};
const int di[] = { 0, -1, 0, 1 };
const int dj[] = { 1, 0, -1, 0 };

int vis[2010][2010];
int from[4][2010][2010];
int cnt[2010][2010];

#define zeloclr(a) memset(a, 0, sizeof a)
int sum_cnt[2010][2010];
int sum_from[4][2010][2010];

void make_2dsum(int a[2010][2010], int s[2010][2010]) {
    rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
    rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
    rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
}

void make_1dsum(int n, int a[2010], int s[2010]) {
    rep(i, n) s[i + 1] = s[i] + a[i];
}

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

    while (cin >> h >> w >> qq) {
        zeloclr(cnt);
        zeloclr(vis);
        zeloclr(from);

        rep(j, w+2) g[0][h] = g[h+1][j] = '0';
        rep(i, h) {
            string s;
            cin >> s;
            g[i+1][0] = '0';
            g[i+1][w+1] = '0';
            rep(j, w) g[i+1][j+1] = s[j];
        }
        ++h; ++w;
        ++h; ++w;

        queue<pair<int,int>> q;
        rep(i, h) {
            rep(j, w) {
                if (g[i][j] == '1' && !vis[i][j]) {
                    cnt[i][j] = 1;
                    q.emplace(i, j);
                    vis[i][j] = true;
                    while (q.size()) {
                        int ci, cj;
                        tie(ci, cj) = q.front();
                        q.pop();
                        rep(d, 4) {
                            int ni = ci + di[d];
                            int nj = cj + dj[d];
                            if (ni >= 0 && nj >= 0 && ni < h && nj < w && g[ni][nj] == '1' && !vis[ni][nj]) {
                                q.emplace(ni, nj);
                                vis[ni][nj] = true;
                                from[d][ni][nj] = 1;
                            }
                        }
                    }
                }
            }
        }

        // show(h, w, from[R]);
        make_2dsum(cnt, sum_cnt);
        rep(i, h) {
            rep(j, w) {
                sum_from[U][i][j + 1] = sum_from[U][i][j] + from[U][i][j];
                sum_from[D][i][j + 1] = sum_from[D][i][j] + from[D][i][j];
            }
        }
        rep(j, w) {
            rep(i, h) {
                sum_from[L][j][i + 1] = sum_from[L][j][i] + from[L][i][j];
                sum_from[R][j][i + 1] = sum_from[R][j][i] + from[R][i][j];
            }
        }
        // dump("from L");
        // show(h, w, from[L]);
        // dump("sum_");
        // show(h + 1, w + 1, sum_from[L]);

        rep(i, qq) {
            int i1, j1, i2, j2;
            cin >> i1 >> j1 >> i2 >> j2;
            ++i2; ++j2;
            int l = sum_from[L][j1][i2] - sum_from[L][j1][i1];
            int d = sum_from[D][i1][j2] - sum_from[D][i1][j1];
            int r = sum_from[R][j2-1][i2] - sum_from[R][j2-1][i1];
            int u = sum_from[U][i2-1][j2] - sum_from[U][i2-1][j1];
            int c = sum_cnt[i2][j2] - sum_cnt[i2][j1] - sum_cnt[i1][j2] + sum_cnt[i1][j1];
            // dump(i1, j1, i2, j2);
            // dump(l, r, u, d, c);
            cout << l + r + u + d + c << '\n';
        }
    }
}


Measured memory_bytes: 179328