#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/*
 * When a forest has k connected components, each connected component is
 * a tree and the number of vertices minus the number of edges in the
 * forest is k. Thus, we can compute the number of connected components
 * in a forest as the number of vertices minus the number of edges.
 * Therefore, for each query, we can compute the answer as follows:
 * - (The number of blue cells in the rectangle)
 * - (The number of horizontally adjacent pairs of two blue cells in
 *    the rectangle)
 * - (The number of vertically adjacent pairs of two blue cells in the
 *    rectangle)
 * Each term in this formula can be computed in O(1) if we pre-compute
 * 2-dimensional sums. Overall it works in O(N M + Q).
 */

const int maxn = 2020;
int U[maxn][maxn], H[maxn][maxn], V[maxn][maxn];
char G[maxn][maxn];
int N,M,Q;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N >> M >> Q) {
        memset(V,0,sizeof(V));
        memset(H,0,sizeof(H));
        memset(U,0,sizeof(U));
        FOR(i,1,N+1) FOR(j,1,M+1)
            cin >> G[i][j];
        FOR(i,1,N+1) FOR(j,1,M+1) {
            U[i][j] = U[i-1][j] + U[i][j-1] - U[i-1][j-1];
            H[i][j] = H[i-1][j] + H[i][j-1] - H[i-1][j-1];
            V[i][j] = V[i-1][j] + V[i][j-1] - V[i-1][j-1];
            /*
             * |-|-|-|
             * | | |1|  To establish the connection, we just need to
             * |-|-|-|  exam the 2 adj cells.
             * | |1|X|
             */
            if (G[i][j] == '1') {
                U[i][j]++;
                H[i][j] += G[i][j-1] == '1';
                V[i][j] += G[i-1][j] == '1';
            }
        }
        FOR(i,0,Q) {
            int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
            const int u =
                U[x2][y2] - U[x2][y1-1] - U[x1-1][y2] + U[x1-1][y1-1];
            /* For the edge count, we need to cut one row/col deeper. */
            const int he =
                H[x2][y2] - H[x2][y1] - H[x1-1][y2] + H[x1-1][y1];
            const int ve =
                V[x2][y2] - V[x2][y1-1] - V[x1][y2] + V[x1][y1-1];
            const int ans = u - ve - he;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 53632