///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii; 
 
const int N = 1005; 
const int mod = 1e9 + 7;
 
#define mul(a, b) ((ll) (a) * (b) % mod)
 
int f[N][N], n, a, b, c, d, fact[N], inv[N][N];
 
inline int Pow(int a, int p) {
    int ret = 1; while(p) {
        if(p & 1) ret = mul(ret, a); 
        a = mul(a, a); 
        p >>= 1;
    } return ret;
}
 
void precalc() {
    fact[0] = 1; 
    for(int i = 1; i < N; ++i) 
        fact[i] = mul(fact[i - 1], i); 
    inv[N - 1][1] = Pow(fact[N - 1], mod - 2); 
    for(int i = N - 2; i >= 0; --i) 
        inv[i][1] = mul(inv[i + 1][1], i + 1); 
    for(int i = 0; i < N; ++i) {
        inv[i][0] = 1; 
        for(int j = 2; j < N; ++j) {
            inv[i][j] = mul(inv[i][j - 1], inv[i][1]); 
        }
    }
}
 
 
int main(int argc, char const *argv[]) {
    precalc();
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d); 
 
    for(int i = 0; i <= n; ++i) f[0][i] = 1;  
    for(int i = 1; i <= n; ++i) {
        for(int j = a; j <= b; ++j) {
            f[i][j] = f[i][j - 1]; 
            for(int k = c; k <= d && j * k <= i; ++k) {
                f[i][j] += mul(fact[i], mul(f[i-j*k][j-1], mul(inv[i-j*k][1], mul(inv[j][k], inv[k][1])))); 
                if(f[i][j] >= mod) f[i][j] -= mod; 
            } 
        }
    }
    printf("%d\n", f[n][b]);
}
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 2005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,m,q,v[N][N],xe[N][N],ye[N][N];
char s[N][N];
int main()
{
	re(n),re(m),re(q);
	for(int i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			v[i][j]=s[i][j]-'0'+v[i-1][j];
			xe[i][j]=(s[i][j]=='1'&&s[i-1][j]=='1')+xe[i-1][j];
			ye[i][j]=(s[i][j]=='1'&&s[i][j-1]=='1')+ye[i][j-1];
		}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			v[i][j]+=v[i][j-1];
			xe[i][j]+=xe[i][j-1];
			ye[i][j]+=ye[i-1][j];
		}
	for(int a,b,c,d;q--;)
	{
		re(a),re(b),re(c),re(d);
		int ans=v[c][d]+v[a-1][b-1]-v[a-1][d]-v[c][b-1];
		ans-=xe[c][d]-xe[a][d]-xe[c][b-1]+xe[a][b-1];
		ans-=ye[c][d]-ye[a-1][d]-ye[c][b]+ye[a-1][b];
		printf("%d\n",ans);
	}
}
