//Now you are making me a boy with luvv...
//I don't want to do this but I'm being forced to ....pls help!!
#include <bits/stdc++.h>
using namespace std;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define ed end()  
#define bg begin()
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
typedef vector< int > vi;
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
const long long MAXN = 4e18 + 1;
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int main(){
                   // ios_base::sync_with_stdio(false);
                    //cin.tie(NULL);
                    //cout.tie(NULL);
 
                     ll t;
                    // cin >> t;
                     t=1;
                     while (t--){
                             ll h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
                             if(m2>m1){
                                 ll diff=(h2-h1)*60 + m2-m1;
                                 cout<<diff-k<<endl;
                             }
                             else{
                                 ll diff=(h2-h1)*60 +m2-m1;
                                 cout<<diff -k<<endl;
                             }
                     }
                    cerr << endl
                                  << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
                      return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 4010
#define Maxm 4010

using namespace std;

int read() {
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while('0' <= c && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}

int N,M,Q;
int mp[Maxn][Maxm],sum1[Maxn][Maxm],sum2[Maxn][Maxm];

int main() {
	N = read(); M = read(); Q = read();
	char ch;
	for(int i = 1;i <= N; i++)
		for(int j = 1;j <= M; j++) {
			int x = i * 2 - 1,y = j * 2 - 1;
			ch = getchar();
			while(ch != '0' && ch != '1') ch = getchar();
			if(ch == '1') mp[x][y] = 1;
		}
	for(int i = 1;i <= N; i++)
		for(int j = 1;j <= M; j++) {
			int x = i * 2 - 1,y = j * 2 - 1;
			if(mp[x][y]) {
				if(mp[x - 2][y]) mp[x - 1][y] = 2;
				if(mp[x + 2][y]) mp[x + 1][y] = 2;
				if(mp[x][y + 2]) mp[x][y + 1] = 2;
				if(mp[x][y - 2]) mp[x][y - 1] = 2;
			}
		}
	for(int i = 1;i < N * 2; i++)
		for(int j = 1;j < M * 2; j++) {
			if(mp[i][j] == 1) sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1] + 1;
			else sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1];
			if(mp[i][j] == 2) sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1] + 1;
			else sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
		}
	int i_1,j_1,i_2,j_2,x_1,y_1,x_2,y_2;
	for(int k = 1;k <= Q; k++) {
		i_1 = read(); j_1 = read(); i_2 = read(); j_2 = read();
		x_1 = i_1 * 2 - 1; y_1 = j_1 * 2 - 1;
		x_2 = i_2 * 2 - 1; y_2 = j_2 * 2 - 1;
		int ans1 = sum1[x_2][y_2] + sum1[x_1 - 1][y_1 - 1] - sum1[x_2][y_1 - 1] - sum1[x_1 - 1][y_2];
		int ans2 = sum2[x_2][y_2] + sum2[x_1 - 1][y_1 - 1] - sum2[x_2][y_1 - 1] - sum2[x_1 - 1][y_2];
		printf("%d\n",ans1 - ans2);
	}
	return 0;
}