#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

struct Int2D {
  int r, c;
  Int2D(int r, int c) : r(r), c(c) {}
};

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

constexpr int DEBUG = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w, q;
  cin >> h >> w >> q;
  auto board = Make2DVector(h, w, 0);
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      board[i][j] = line[j] == '1';
    }
  }

  if (DEBUG) cout << "DEBUG 1" << endl;

  auto root_bit = Make2DVector(h, w, 0);
  auto from_l = Make2DVector(h, w, 0);
  auto from_r = Make2DVector(h, w, 0);
  auto from_u = Make2DVector(h, w, 0);
  auto from_d = Make2DVector(h, w, 0);
  auto visited = Make2DVector(h, w, 0);

  function<void(int, int)> dfs = [&](int r, int c) {
    visited[r][c] = true;
    // To R
    if (c + 1 < w && board[r][c + 1] && !visited[r][c + 1]) {
      from_l[r][c + 1] = 1;
      dfs(r, c + 1);
    }
    // To L
    if (c - 1 >= 0 && board[r][c - 1] && !visited[r][c - 1]) {
      from_r[r][c - 1] = 1;
      dfs(r, c - 1);
    }
    // To D
    if (r + 1 < h && board[r + 1][c] && !visited[r + 1][c]) {
      from_u[r + 1][c] = 1;
      dfs(r + 1, c);
    }
    // To U
    if (r - 1 >= 0 && board[r - 1][c] && !visited[r - 1][c]) {
      from_d[r - 1][c] = 1;
      dfs(r - 1, c);
    }
  };

  for (int r = 0; r < h; r++) {
    for (int c = 0; c < w; c++) {
      if (board[r][c] && !visited[r][c]) {
        root_bit[r][c] = 1;
        dfs(r, c);
      }
    }
  }

  if (DEBUG) cout << "DEBUG 2" << endl;

  auto cum_root_bit = Make2DVector(h, w, 0);
  for (int r = 0; r < h; r++) {
    for (int c = 0; c < w; c++) {
      if (r == 0 && c == 0) {
        cum_root_bit[r][c] = root_bit[r][c];
      } else if (r == 0) {
        cum_root_bit[r][c] = cum_root_bit[r][c - 1] + root_bit[r][c];
      } else if (c == 0) {
        cum_root_bit[r][c] = cum_root_bit[r - 1][c] + root_bit[r][c];
      } else {
        cum_root_bit[r][c] = cum_root_bit[r - 1][c]
            + cum_root_bit[r][c - 1]
            - cum_root_bit[r - 1][c - 1]
            + root_bit[r][c];
      }
    }
  }

  if (DEBUG) cout << "DEBUG 3" << endl;

  auto cum_from_l = Make2DVector(h, w, 0);
  auto cum_from_r = Make2DVector(h, w, 0);
  auto cum_from_u = Make2DVector(h, w, 0);
  auto cum_from_d = Make2DVector(h, w, 0);
  for (int r = 0; r < h; r++) {
    for (int c = 0; c < w; c++) {
      if (r == 0) {
        cum_from_l[r][c] = from_l[r][c];
        cum_from_r[r][c] = from_r[r][c];
      } else {
        cum_from_l[r][c] = cum_from_l[r - 1][c] + from_l[r][c];
        cum_from_r[r][c] = cum_from_r[r - 1][c] + from_r[r][c];
      }

      if (c == 0) {
        cum_from_u[r][c] = from_u[r][c];
        cum_from_d[r][c] = from_d[r][c];
      } else {
        cum_from_u[r][c] = cum_from_u[r][c - 1] + from_u[r][c];
        cum_from_d[r][c] = cum_from_d[r][c - 1] + from_d[r][c];
      }
    }
  }

  if (DEBUG) {
    cout << "dump: from_r" << endl;
    for (int r = 0; r < h; r++) {
      for (int c = 0; c < w; c++) {
        cout << from_r[r][c] << " ";
      }
      cout << endl;
    }
  }

  if (DEBUG) cout << "DEBUG 4" << endl;

  for (int i = 0; i < q; i++) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--;
    c1--;
    r2--;
    c2--;

    int ans = 0;
    ans += cum_root_bit[r2][c2];
    if (r1 - 1 >= 0) ans -= cum_root_bit[r1 - 1][c2];
    if (c1 - 1 >= 0) ans -= cum_root_bit[r2][c1 - 1];
    if (r1 - 1 >= 0 && c1 - 1 >= 0) ans += cum_root_bit[r1 - 1][c1 - 1];

    if (DEBUG) cout << "root-ans: " << ans << endl;

    ans += cum_from_l[r2][c1];
    if (r1 - 1 >= 0) ans -= cum_from_l[r1 - 1][c1];

    if (DEBUG) cout << "l-ans: " << ans << endl;

    ans += cum_from_r[r2][c2];
    if (r1 - 1 >= 0) ans -= cum_from_r[r1 - 1][c2];

    if (DEBUG) cout << "r-ans: " << ans << endl;

    ans += cum_from_u[r1][c2];
    if (c1 - 1 >= 0) ans -= cum_from_u[r1][c1 - 1];

    if (DEBUG) cout << "u-ans: " << ans << endl;

    ans += cum_from_d[r2][c2];
    if (c1 - 1 >= 0) ans -= cum_from_d[r2][c1 - 1];

    if (DEBUG) cout << "d-ans: " << ans << endl;

    cout << ans << endl;
  }
}

Measured memory_bytes: 191744