#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const long long N = 1e3 + 7;
long long a[N][N];
long long n, m, q;
long long ps[N][N];
long long dp[N], s[N];
long long solve(long long x, long long y) {
  if (!x || !y) return 0;
  if (x <= n && y <= m) return ps[x][y];
  if (x > n && x % n == 0 && __builtin_popcount(x / n) == 1) return (x / 2) * y;
  if (y > m && y % m == 0 && __builtin_popcount(y / m) == 1) return (y / 2) * x;
  long long kx = log2(x / n);
  long long ky = log2(y / m);
  if (kx > ky || (kx == ky && y <= m))
    return solve((1 << kx) * n, y) + (x - (1 << kx) * n) * y -
           solve(x - (1 << kx) * n, y);
  else
    return solve(x, (1 << ky) * m) + x * (y - (1 << ky) * m) -
           solve(x, y - (1 << ky) * m);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> q;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '1') a[i][j] = 1;
      ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + a[i][j];
    }
  dp[0] = ps[n][m];
  s[0] = n * m;
  for (long long i = 1; i <= 30; i++) {
    dp[i] = 2 * s[i - 1];
    s[i] = (1 << i) * n * (1 << i) * m;
  }
  while (q--) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << solve(x2, y2) - solve(x2, y1 - 1) - solve(x1 - 1, y2) +
                solve(x1 - 1, y1 - 1)
         << '\n';
  }
}
