#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n,m,q;
  scanf("%d%d%d",&n,&m,&q);
  static int B[2010][2010];
  for(int i=0;i<n;i++){
    char s[2010];
    scanf("%s",s);
    for(int j=0;j<m;j++){
      B[i][j]=(s[j]=='1');
    }
  }
  static int D[2010][2010];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      D[i][j]=-1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(D[i][j]!=-1||!B[i][j]){
	continue;
      }
      D[i][j]=0;
      queue<pair<int,int > > Q;
      Q.push(make_pair(i,j));
      int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
      while(!Q.empty()){
	pair<int,int> p=Q.front();
	Q.pop();
	for(int v=0;v<4;v++){
	  int x=p.first+dx[v],y=p.second+dy[v];
	  if(0<=x&&x<n&&0<=y&&y<m&&D[x][y]==-1&&B[x][y]){
	    D[x][y]=D[p.first][p.second]+1;
	    Q.push(make_pair(x,y));
	  }
	}
      }
    }
  }
  static int S1[2010][2010],S2[2010][2010];
  for(int i=0;i<n;i++){
    S1[i][0]=0;
    for(int j=0;j<m;j++){
      S1[i][j+1]=S1[i][j]+(D[i][j]==0?1:0);
    }
  }
  for(int j=0;j<=m;j++){
    S2[0][j]=0;
    for(int i=0;i<n;i++){
      S2[i+1][j]=S2[i][j]+S1[i][j];
      //printf("%d %d %d\n",i+1,j,S2[i+1][j]);
    }
  }
  static int A1[2010][2010],A2[2010][2010],A3[2010][2010],A4[2010][2010];
  for(int i=0;i<n;i++){
    A1[i][0]=0;
    bool b=0;
    for(int j=0;j<m;j++){
      if(i>0&&B[i-1][j]&&B[i][j]&&D[i-1][j]<D[i][j]){
	A1[i][j+1]=A1[i][j]+(!b?1:0);
	b=1;
      }
      else{
	A1[i][j+1]=A1[i][j];
	b=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    A2[i][0]=0;
    bool b=0;
    for(int j=0;j<m;j++){
      if(i+1<n&&B[i+1][j]&&B[i][j]&&D[i+1][j]<D[i][j]){
	A2[i][j+1]=A2[i][j]+(!b?1:0);
	b=1;
      }
      else{
	A2[i][j+1]=A2[i][j];
	b=0;
      }
    }
  }
  for(int j=0;j<m;j++){
    A1[0][j]=0;
    bool b=0;
    for(int i=0;i<n;i++){
      if(j>0&&B[i][j-1]&&B[i][j]&&D[i][j-1]<D[i][j]){
	A3[i+1][j]=A3[i][j]+(!b?1:0);
	b=1;
      }
      else{
	A3[i+1][j]=A3[i][j];
	b=0;
      }
    }
  }
  for(int j=0;j<m;j++){
    A4[0][j]=0;
    bool b=0;
    for(int i=0;i<n;i++){
      if(j+1<m&&B[i][j+1]&&B[i][j]&&D[i][j+1]<D[i][j]){
	A4[i+1][j]=A4[i][j]+(!b?1:0);
	b=1;
      }
      else{
	A4[i+1][j]=A4[i][j];
	b=0;
      }
    }
  }
  while(q--){
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    x1--,y1--,x2--,y2--;
    int ret=S2[x2+1][y2+1]-S2[x1][y2+1]-S2[x2+1][y1]+S2[x1][y1];
    //printf("1 %d\n",ret);
    ret+=(x1>0&&B[x1-1][y1]&&B[x1][y1]&&D[x1-1][y1]<D[x1][y1]?1:0)+A1[x1][y2+1]-A1[x1][y1+1];
    ret+=(x2+1<n&&B[x2+1][y1]&&B[x2][y1]&&D[x2+1][y1]<D[x2][y1]?1:0)+A2[x2][y2+1]-A2[x2][y1+1];
    ret+=(y1>0&&B[x1][y1-1]&&B[x1][y1]&&D[x1][y1-1]<D[x1][y1]?1:0)+A3[x2+1][y1]-A3[x1+1][y1];
    ret+=(y2+1<m&&B[x1][y2+1]&&B[x1][y2]&&D[x1][y2+1]<D[x1][y2]?1:0)+A4[x2+1][y2]-A4[x1+1][y2];
    //printf("2 %d\n",ret);
    if(x1>0&&y1>0&&B[x1][y1]&&B[x1-1][y1]&&B[x1][y1-1]&&D[x1-1][y1]<D[x1][y1]&&D[x1][y1-1]<D[x1][y1]){
      ret--;
    }
    if(x1>0&&y2+1<m&&B[x1][y2]&&B[x1-1][y2]&&B[x1][y2+1]&&D[x1-1][y2]<D[x1][y2]&&D[x1][y2+1]<D[x1][y2]){
      ret--;
    }
    if(x2+1<n&&y1>0&&B[x2][y1]&&B[x2+1][y1]&&B[x2][y1-1]&&D[x2+1][y1]<D[x2][y1]&&D[x2][y1-1]<D[x2][y1]){
      ret--;
    }
    if(x2+1<n&&y2+1<m&&B[x2][y2]&&B[x2+1][y2]&&B[x2][y2+1]&&D[x2+1][y2]<D[x2][y2]&&D[x2][y2+1]<D[x2][y2]){
      ret--;
    }
    printf("%d\n",ret);
  }
  return 0;
}


Measured memory_bytes: 128000