#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
//#define int long long

const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, m, q;
string s[5000];
int cnt[2500][2500];
int edg[2500][2500];

int ci[4] = {-1, 1, 0, 0};
int cj[4] = {0, 0, 1, -1};

bool ok(int a, int b)
{
    return (0 <= a && a < n && 0 <= b && b < m && s[a][b] == '1');
}

int hor[2500][2500];
int ver[2500][2500];

int Cnt(int a, int b)
{
    if (a < 0 || b < 0) return 0;
    return cnt[a][b];
}

int Edg(int a, int b)
{
    if (a < 0 || b < 0) return 0;
    return edg[a][b];
}

int Hor(int a, int b)
{
    if (a < 0 || b < 0) return 0;
    return hor[a][b];
}

int Ver(int a, int b)
{
    if (a < 0 || b < 0) return 0;
    swap(a, b);
    return ver[a][b];
}

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m >> q;
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cnt[i][j] = (i > 0 ? cnt[i - 1][j] : 0) + (j > 0 ? cnt[i][j - 1] : 0) - (i > 0 && j > 0 ? cnt[i - 1][j - 1] : 0);
            edg[i][j] = (i > 0 ? edg[i - 1][j] : 0) + (j > 0 ? edg[i][j - 1] : 0) - (i > 0 && j > 0 ? edg[i - 1][j - 1] : 0);
            if (s[i][j] == '1')
            {
                cnt[i][j]++;
                for (int k = 0; k < 4; k++)
                {
                    if (ok(i + ci[k], j + cj[k])) edg[i][j]++;
                }
            }
        }
    }
    for (int i = 0; i + 1 < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (j) hor[i][j] = hor[i][j - 1];
            hor[i][j] += (s[i][j] == '1' && s[i + 1][j] == '1');
        }
    }
    for (int j = 0; j + 1 < m; j++)
    {
        for (int i = 0; i < n; i++)
        {
            if (i) ver[i][j] = ver[i - 1][j];
            ver[i][j] += (s[i][j] == '1' && s[i][j + 1] == '1');
        }
    }
    while (q--)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, c--, b--, d--;
        int v = Cnt(c, d) - Cnt(a - 1, d) - Cnt(c, b - 1) + Cnt(a - 1, b - 1);
        int e = Edg(c, d) - Edg(a - 1, d) - Edg(c, b - 1) + Edg(a - 1, b - 1);
        e -= Hor(a - 1, d) - Hor(a - 1, b - 1);
        e -= Hor(c, d) - Hor(c, b - 1);
        e -= Ver(b - 1, c) - Ver(b - 1, a - 1);
        e -= Ver(d, c) - Ver(d, a - 1);
        cout << v - e / 2 << "\n";
    }
}


Measured memory_bytes: 94208