#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

// http://agc015.contest.atcoder.jp/tasks/agc015_c

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  size_t n, m, q;
  cin >> n >> m >> q;
  vector<string> a(n);
  cin >> a;

  const size_t nil = -1;
  vector<vector<size_t>> fen(n, vector<size_t>(m));
  vector<vector<size_t>> idx(n, vector<size_t>(m, nil));  // dfs id's

  for(size_t i = 0; i < n; ++i)
    for(size_t j = 0; j < m; ++j)
      if(a[i][j] == '1' && idx[i][j] == nil)
      {
        ++fen[i][j];
        size_t cnt = 0;
        idx[i][j] = cnt;
        queue<pair<size_t, size_t>> q;
        for(q.push({i, j}); !q.empty(); q.pop())
        {
          const auto x = q.front().first;
          const auto y = q.front().second;
          if(x && a[x - 1][y] == '1' && idx[x - 1][y] == nil)
          {
            idx[x - 1][y] = ++cnt;
            q.push({x - 1, y});
          }
          if(x + 1 < n && a[x + 1][y] == '1' && idx[x + 1][y] == nil)
          {
            idx[x + 1][y] = ++cnt;
            q.push({x + 1, y});
          }
          if(y && a[x][y - 1] == '1' && idx[x][y - 1] == nil)
          {
            idx[x][y - 1] = ++cnt;
            q.push({x, y - 1});
          }
          if(y + 1 < m && a[x][y + 1] == '1' && idx[x][y + 1] == nil)
          {
            idx[x][y + 1] = ++cnt;
            q.push({x, y + 1});
          }
        }
      }

  for(size_t i = 0; i < n; ++i)
    for(size_t j = 0; j < m; ++ j)
      fen[i][j] += (i ? fen[i - 1][j] : 0)
        + (j ? fen[i][j - 1] : 0)
        - (i && j ? fen[i - 1][j - 1] : 0);

  vector<vector<pair<size_t, size_t>>>
    row(n, vector<pair<size_t, size_t>>(m));
  for(size_t i = 0; i + 1 < n; ++i)
  {
    for(size_t j = 0; j < m; ++j)
      if(a[i][j] == '1' && a[i + 1][j] == '1')
      {
        if(idx[i][j] < idx[i + 1][j])
          ++row[i][j].first;
        else
          ++row[i][j].second;
      }

    for(size_t j = 1; j < m; ++j)
    {
      row[i][j].first += row[i][j - 1].first;
      row[i][j].second += row[i][j - 1].second;
    }
  }

  vector<vector<pair<size_t, size_t>>>
    col(m, vector<pair<size_t, size_t>>(n));
  for(size_t j = 0; j + 1 < m; ++j)
  {
    for(size_t i = 0; i < n; ++i)
      if(a[i][j] == '1' && a[i][j + 1] == '1')
      {
        if(idx[i][j] < idx[i][j + 1])
          ++col[j][i].first;
        else
          ++col[j][i].second;
      }

    for(size_t i = 1; i < n; ++i)
    {
      col[j][i].first += col[j][i - 1].first;
      col[j][i].second += col[j][i - 1].second;
    }
  }

  for(size_t x0, y0, x1, y1; q; --q)
  {
    cin >> x0 >> y0 >> x1 >> y1;
    --x0; --y0; --x1; --y1;
    int64_t out = fen[x1][y1]
      - (y0 ? fen[x1][y0 - 1] : 0)
      - (x0 ? fen[x0 - 1][y1] : 0)
      + (x0 && y0 ? fen[x0 - 1][y0 - 1] : 0);

    DEBUG(out);
    if(x0)
      out += row[x0 - 1][y1].first - (y0 ? row[x0 - 1][y0 - 1].first : 0);

    out += row[x1][y1].second - (y0 ? row[x1][y0 - 1].second : 0);

    if(y0)
      out += col[y0 - 1][x1].first - (x0 ? col[y0 - 1][x0 - 1].first : 0);

    out += col[y1][x1].second - (x0 ? col[y1][x0 - 1].second : 0);

    cout << out << '\n';

  }

  return EXIT_SUCCESS;
}


Measured memory_bytes: 195072