#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

string to_string(const string &s) { return s; }

template <typename T, typename U>
string to_string(const P<T, U> &p) {
    string ret = "(";
    ret += to_string(p.first);
    ret += ", ";
    ret += to_string(p.second);
    ret += ")";
    return move(ret);
}

template <typename T>
string to_string(const V<T> &v) {
    string ret = "{";
    for(const T &t : v) {
        ret += to_string(t);
        ret += ", ";
    }
    ret += "}";
    return move(ret);
}

template <typename T>
void debug_func(const T &t, const string &s = "") {
    if(s.size()) cout << s << " = ";
    cout << to_string(t) << DEBUG_ENDL_S(s);
}

template <typename T>
void debug_func_mult(int idx, const V<string> &names, const T &t) {
    debug_func(t, names[idx]);
}

template <typename T>
void debug_func_mult(const V<string> &names, const T &t) {
    debug_func(t, names[0]);
}

template <typename Head, typename... Tail>
void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[idx]);
    debug_func_mult(idx + 1, names, args...);
}

template <typename Head, typename... Tail>
void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[0]);
    debug_func_mult(1, names, args...);
}

V<string> split_names(string &&s) {
    replace(ALL(s), ' ', ',');
    V<string> ret;
    istringstream ss(s);
    string t;
    while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t));
    return move(ret);
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

ll N, M;
V<string> S;
VV<ll> sum_nodes, sum_edges;
VV<ll> sum_edges_left, sum_edges_right, sum_edges_up, sum_edges_down;

bool check_range(ll h, ll w) { 
    return 0 <= h && h < N &&
           0 <= w && w < M;
}

bool exist_edge(ll h0, ll w0, ll h1, ll w1) {
    return check_range(h0, w0) &&
           check_range(h1, w1) &&
           S[h0][w0] == '1' &&
           S[h1][w1] == '1';
}

void calc_sum() {
    ll dh[] = { -1, 0 };
    ll dw[] = { 0, -1 };
    sum_nodes = VV<ll>(N + 1, V<ll>(M + 1, 0));
    sum_edges = VV<ll>(N + 1, V<ll>(M + 1, 0));
    for(ll h = 0; h < N; h++) {
        for(ll w = 0; w < M; w++) {
            if(S[h][w] == '1') {
                sum_nodes[h + 1][w + 1]++;
                for(ll i = 0; i < 2; i++) {
                    ll nh = h + dh[i];
                    ll nw = w + dw[i];
                    sum_edges[h + 1][w + 1] += exist_edge(h, w, nh, nw);
                }
            }
        }
    }
    for(ll h = 0; h < N; h++) {
        for(ll w = 0; w <= M; w++) {
            sum_nodes[h + 1][w] += sum_nodes[h][w];
            sum_edges[h + 1][w] += sum_edges[h][w];
        }
    }
    for(ll h = 0; h <= N; h++) {
        for(ll w = 0; w < M; w++) {
            sum_nodes[h][w + 1] += sum_nodes[h][w];
            sum_edges[h][w + 1] += sum_edges[h][w];
        }
    }
}

void calc_next_edges() {
    sum_edges_left  = VV<ll>(M, V<ll>(N + 1, 0));
    sum_edges_right = VV<ll>(M, V<ll>(N + 1, 0));
    sum_edges_up    = VV<ll>(N, V<ll>(M + 1, 0));
    sum_edges_down  = VV<ll>(N, V<ll>(M + 1, 0));
    for(ll h = 0; h < N; h++) {
        for(ll w = 0; w < M; w++) {
            sum_edges_left[w][h + 1]  += exist_edge(h, w, h, w - 1);
            sum_edges_right[w][h + 1] += exist_edge(h, w, h, w + 1);
            sum_edges_up[h][w + 1]    += exist_edge(h, w, h - 1, w);
            sum_edges_down[h][w + 1]  += exist_edge(h, w, h + 1, w);
        }
    }
    for(ll h = 0; h < N; h++) {
        for(ll w = 0; w < M; w++) {
            sum_edges_left[w][h + 1] += sum_edges_left[w][h];
            sum_edges_right[w][h + 1] += sum_edges_right[w][h];
        }
    }
    for(ll w = 0; w < M; w++) {
        for(ll h = 0; h < N; h++) {
            sum_edges_up[h][w + 1] += sum_edges_up[h][w];
            sum_edges_down[h][w + 1] += sum_edges_down[h][w];
        }
    }
}

ll __query(ll h0, ll w0, ll h1, ll w1, bool node) {
    const auto &sum = (node ? sum_nodes : sum_edges);
    ll ret = 0;
    ret += sum[h1][w1];
    ret -= sum[h0][w1];
    ret -= sum[h1][w0];
    ret += sum[h0][w0];
    return ret;
}

ll calc_nodes(ll h0, ll w0, ll h1, ll w1) { return __query(h0, w0, h1 + 1, w1 + 1, true); }
ll calc_edges(ll h0, ll w0, ll h1, ll w1) {
    ll ret = __query(h0, w0, h1 + 1, w1 + 1, false);
    DEBUG(ret);
    ret -= sum_edges_left[w0][h1 + 1] - sum_edges_left[w0][h0];
    //ret -= sum_edges_right[w1][h1 + 1] - sum_edges_right[w1][h0];
    ret -= sum_edges_up[h0][w1 + 1] - sum_edges_up[h0][w0];
    //ret -= sum_edges_down[h1][w1 + 1] - sum_edges_down[h1][w0];
    return ret;
}

ll query(ll x0, ll y0, ll x1, ll y1) {
    ll nodes = calc_nodes(x0, y0, x1, y1);
    ll edges = calc_edges(x0, y0, x1, y1);
    DEBUG(nodes, edges);
    return nodes - edges;
}

int main() {
    ll Q;
    cin >> N >> M >> Q;
    S = V<string>(N);
    for(auto &s : S) cin >> s;
    calc_sum();
    calc_next_edges();
    DEBUG(sum_nodes, sum_edges);
    DEBUG(sum_edges_left,
          sum_edges_right,
          sum_edges_up,
          sum_edges_down);
    for(ll QQ = 0; QQ < Q; QQ++) {
        ll x0, y0, x1, y1;
        cin >> x0 >> y0
            >> x1 >> y1;
        cout << query(x0 - 1, y0 - 1,
                      x1 - 1, y1 - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 194560