#include<bits/stdc++.h>
using namespace std;
template<class T>inline void read(T &re)
{
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	re=ch-48;
	while((ch=getchar())>='0'&&ch<='9')
	re=(re<<3)+(re<<1)+ch-48;
}
int n,m,Q,pt[4005][4005],eg[4005][4005];
char mp[2005][2005],s[4005][4005];
int main()
{
//	freopen("duty.in","r",stdin);
//	freopen("duty.out","w",stdout);
	read(n);read(m);read(Q);
	for(register int i=1;i<=n;++i){
		scanf("%s",mp[i]+1);
		for(register int j=1;j<=m;++j)
		s[2*i-1][2*j-1]=mp[i][j];
	}
		
	for(register int i=1;i<=n;++i){
		int x=2*i-1,y;
		for(register int j=1;j<=m;++j){
			y=2*j-1;
			if(s[x][y]=='1'){
				if(s[x+2][y]=='1')
					s[x+1][y]='2';
				if(s[x][y+2]=='1')
					s[x][y+1]='2';
			}
		}
	}
	
	for(register int i=1;i<=2*n-1;++i){
		for(register int j=1;j<=2*m-1;++j){
			pt[i][j]=(s[i][j]=='1')+pt[i-1][j]+pt[i][j-1]-pt[i-1][j-1];
			eg[i][j]=(s[i][j]=='2')+eg[i-1][j]+eg[i][j-1]-eg[i-1][j-1];
		}
	}
	int u,v,w,z,ans1,ans2;
	for(register int i=1;i<=Q;++i){
		read(u);read(v);read(w);read(z);
		u=2*u-1,v=2*v-1,w=2*w-1,z=2*z-1;
		ans1=pt[w][z]+pt[u-1][v-1]-pt[u-1][z]-pt[w][v-1];
		ans2=eg[w][z]+eg[u-1][v-1]-eg[u-1][z]-eg[w][v-1];
		printf("%d\n",ans1-ans2);
	}
}
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<functional>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
#define N 123456 
int num = 0;

int ToInt(string str) {
	int a = 0, n = (int)str.size();
	for(int i = 0; i < n; i++) {
		a += (str[i]-'0') * (int)pow(10., (double)(n-i-1));
	}
	return a;
}

string ToString(int a, int l) {
	string str;
	if(l == 6) str = "000000";
	if(l == 5) str = "00000";
	if(l == 4) str = "0000";
	if(l == 3) str = "000";
	if(l == 2) str = "00";
	if(l == 1) str = "0";
	for(int i = 0; i < l; i++) {
		int n = a / (int)pow(10., (double)(l-i-1));
			str[i] = n + '0';
			a -= n * (int)pow(10., (double)(l-i-1));
			}

	return str;
}
int dia(int h, int w) {
	return h*h + w*w;
}

void tan(int d) {
		for(int i = 1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == d) {
					cout << i << " " << j <<endl;
					return;
				} else if(dia(i, j) > d) break;
			}
		}
		tan(d + 1);
}

int main(){
	int h, w;
	while(cin >> h >> w) {
		if(h + w == 0) break;
		bool bo2 = false;
		for(int i = h+1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == dia(h, w)) {
					h = i;
					w = j;
					bo2 = true;
					break;
				} else if(dia(i, j) > dia(h,w)) break;
			}
			if(bo2) break;
		}
		if(bo2) cout << h << " " << w <<endl;
		else tan(dia(h, w) + 1);
	}
	return 0;
}