#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
//#define int long long
//----------------------------------------------------
int h, w, q;
bool a[2003][2003];
int h_plus[2002][2002], h_minus[2003][2003];
int w_plus[2002][2002], w_minus[2003][2003];
//差が1だった時用

int edge[2003][2003];
//端っこ（次数が1の頂点）

int fork[2003][2003];
//枝分かれ（次数が3以上の頂点）

int up_e[2003][2003], up_f[2003][2003];
//上が存在しないとしたときの1行だけの端っこと分かれ道
int down_e[2003][2003], down_f[2003][2003];
int lef_e[2003][2003], lef_f[2003][2003];
int rig_e[2003][2003], rig_f[2003][2003];

int lonely[2003][2003];
//独りぼっち
signed main() {
	cin >> h >> w >> q;
	for (int i = 1; i <= h; i++) {
		string s;
		cin >> s;
		for (int j = 1; j <= w; j++) {
			a[i][j] = (int)(s[j - 1] - '0');
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			h_plus[i][j] += h_plus[i - 1][j]; h_minus[i][j] += h_minus[i - 1][j];
			w_plus[i][j] += w_plus[i][j - 1]; w_minus[i][j] += w_minus[i][j - 1];

			edge[i][j] = edge[i - 1][j] + edge[i][j - 1] - edge[i - 1][j - 1];
			fork[i][j] = fork[i - 1][j] + fork[i][j - 1] - fork[i - 1][j - 1];

			up_e[i][j] += up_e[i][j - 1]; up_f[i][j] += up_f[i][j - 1];
			down_e[i][j] += down_e[i][j - 1]; down_f[i][j] += down_f[i][j - 1];
			lef_e[i][j] += lef_e[i - 1][j]; lef_f[i][j] += lef_f[i - 1][j];
			rig_e[i][j] += rig_e[i - 1][j]; rig_f[i][j] += rig_f[i - 1][j];

			lonely[i][j] = lonely[i][j - 1] + lonely[i - 1][j] - lonely[i - 1][j - 1];

			if (!a[i][j]) continue;
			if (!a[i - 1][j] && !a[i][j - 1] && !a[i + 1][j] && !a[i][j + 1]) {
				a[i][j] = 0; lonely[i][j]++;
				continue;
			}

			int sum = 0;
			if (a[i - 1][j]) sum++;
			if (a[i + 1][j]) sum++;
			if (a[i][j - 1]) sum++;
			if (a[i][j + 1]) sum++;

			if (sum == 1) {
				edge[i][j]++;
			}
			else if (sum > 2) {
				fork[i][j] += sum - 2;
				up_f[i][j] += sum - a[i - 1][j] - 2;
				down_f[i][j] += sum - a[i + 1][j] - 2;
				lef_f[i][j] += sum - a[i][j - 1] - 2;
				rig_f[i][j] += sum - a[i][j + 1] - 2;
			}

			if (sum - a[i - 1][j] == 0) up_e[i][j]++;
			if (sum - a[i - 1][j] <= 1) up_e[i][j]++;
			if (sum - a[i + 1][j] == 0) down_e[i][j]++;
			if (sum - a[i + 1][j] <= 1) down_e[i][j]++;
			if (sum - a[i][j - 1] == 0) lef_e[i][j]++;
			if (sum - a[i][j - 1] <= 1) lef_e[i][j]++;
			if (sum - a[i][j + 1] == 0) rig_e[i][j]++;
			if (sum - a[i][j + 1] <= 1) rig_e[i][j]++;

			if (!a[i - 1][j]) h_plus[i][j]++;
			if (!a[i + 1][j]) h_minus[i + 1][j]++;
			if (!a[i][j - 1]) w_plus[i][j]++;
			if (!a[i][j + 1]) w_minus[i][j + 1]++;
		}
	}
	for (int i = 0; i < q; i++) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int ans = lonely[x2][y2] - lonely[x1 - 1][y2] - lonely[x2][y1 - 1] + lonely[x1 - 1][y1 - 1];
		if (x1 == x2 && y1 == y2) {
			cout << ans + a[x1][y1] << endl;
		}
		else if (x1 == x2) {
			cout << ans + w_plus[x1][y2] - w_minus[x1][y1] << endl;
		}
		else if (y1 == y2) {
			cout << ans + h_plus[x2][y1] - h_minus[x1][y1] << endl;
		}
		else {
			int sum = 0;
			sum += edge[x2 - 1][y2 - 1] - edge[x1][y2 - 1] - edge[x2 - 1][y1] + edge[x1][y1];
			sum -= fork[x2 - 1][y2 - 1] - fork[x1][y2 - 1] - fork[x2 - 1][y1] + fork[x1][y1];

			sum += up_e[x1][y2 - 1] - up_e[x1][y1];
			sum -= up_f[x1][y2 - 1] - up_f[x1][y1];
			sum += down_e[x2][y2 - 1] - down_e[x2][y1];
			sum -= down_f[x2][y2 - 1] - down_f[x2][y1];
			sum += lef_e[x2 - 1][y1] - lef_e[x1][y1];
			sum -= lef_f[x2 - 1][y1] - lef_f[x1][y1];
			sum += rig_e[x2 - 1][y2] - rig_e[x1][y2];
			sum -= rig_f[x2 - 1][y2] - rig_f[x1][y2];

			int res = a[x1 + 1][y1] + a[x1][y1 + 1];
			if (a[x1][y1] && res == 0) ans++;
			if (a[x1][y1] && res == 1) sum++;
			res = a[x1 + 1][y2] + a[x1][y2 - 1];
			if (a[x1][y2] && res == 0) ans++;
			if (a[x1][y2] && res == 1) sum++;
			res = a[x2 - 1][y1] + a[x2][y1 + 1];
			if (a[x2][y1] && res == 0) ans++;
			if (a[x2][y1] && res == 1) sum++;
			res = a[x2 - 1][y2] + a[x2][y2 - 1];
			if (a[x2][y2] && res == 0) ans++;
			if (a[x2][y2] && res == 1) sum++;

			cout << ans + sum / 2 << endl;
		}
	}
}


Measured memory_bytes: 240768