package main
import (
"bufio"
"io"
"os"
"strconv"
)
var data []byte
var ptr int
func nextInt() int {
n := len(data)
for ptr < n && data[ptr] <= ' ' {
ptr++
}
val := 0
for ptr < n && data[ptr] > ' ' {
val = val*10 + int(data[ptr]-'0')
ptr++
}
return val
}
func nextString() string {
n := len(data)
for ptr < n && data[ptr] <= ' ' {
ptr++
}
start := ptr
for ptr < n && data[ptr] > ' ' {
ptr++
}
return string(data[start:ptr])
}
func main() {
data, _ = io.ReadAll(os.Stdin)
n := nextInt()
m := nextInt()
q := nextInt()
ps := make([][]int, n+1)
for i := 0; i <= n; i++ {
ps[i] = make([]int, m+1)
}
for i := 1; i <= n; i++ {
s := nextString()
for j := 1; j <= m; j++ {
v := 0
if s[j-1] == '1' {
v = 1
}
ps[i][j] = ps[i-1][j] + ps[i][j-1] - ps[i-1][j-1] + v
}
}
A := n + 2
B := m + 2
C := n + 2
D := m + 2
sA := B * C * D
sB := C * D
sC := D
arr := make([]int32, A*B*C*D)
for x1 := 1; x1 <= n; x1++ {
for y1 := 1; y1 <= m; y1++ {
for x2 := x1; x2 <= n; x2++ {
for y2 := y1; y2 <= m; y2++ {
ones := ps[x2][y2] - ps[x1-1][y2] - ps[x2][y1-1] + ps[x1-1][y1-1]
if ones == 0 {
a1, a2 := 1, x1
b1, b2 := 1, y1
c1, c2 := x2, n
d1, d2 := y2, m
for mask := 0; mask < 16; mask++ {
aa, bb, cc, dd := a1, b1, c1, d1
sign := int32(1)
if mask&1 != 0 {
aa = a2 + 1
sign = -sign
}
if mask&2 != 0 {
bb = b2 + 1
sign = -sign
}
if mask&4 != 0 {
cc = c2 + 1
sign = -sign
}
if mask&8 != 0 {
dd = d2 + 1
sign = -sign
}
arr[aa*sA+bb*sB+cc*sC+dd] += sign
}
}
}
}
}
}
for a := 1; a <= n; a++ {
offA := a * sA
offAm := (a - 1) * sA
for b := 1; b <= m; b++ {
offAB := offA + b*sB
offAmB := offAm + b*sB
for c := 1; c <= n; c++ {
offABC := offAB + c*sC
offAmBC := offAmB + c*sC
for d := 1; d <= m; d++ {
arr[offABC+d] += arr[offAmBC+d]
}
}
}
}
for a := 1; a <= n; a++ {
offA := a * sA
for b := 1; b <= m; b++ {
offAB := offA + b*sB
offABm := offA + (b-1)*sB
for c := 1; c <= n; c++ {
offABC := offAB + c*sC
offABmC := offABm + c*sC
for d := 1; d <= m; d++ {
arr[offABC+d] += arr[offABmC+d]
}
}
}
}
for a := 1; a <= n; a++ {
offA := a * sA
for b := 1; b <= m; b++ {
offAB := offA + b*sB
for c := 1; c <= n; c++ {
offABC := offAB + c*sC
offABCm := offAB + (c-1)*sC
for d := 1; d <= m; d++ {
arr[offABC+d] += arr[offABCm+d]
}
}
}
}
for a := 1; a <= n; a++ {
offA := a * sA
for b := 1; b <= m; b++ {
offAB := offA + b*sB
for c := 1; c <= n; c++ {
offABC := offAB + c*sC
for d := 1; d <= m; d++ {
arr[offABC+d] += arr[offABC+d-1]
}
}
}
}
out := make([]byte, 0, q*8)
for ; q > 0; q-- {
a := nextInt()
b := nextInt()
c := nextInt()
d := nextInt()
out = strconv.AppendInt(out, int64(arr[a*sA+b*sB+c*sC+d]), 10)
out = append(out, '\n')
}
w := bufio.NewWriterSize(os.Stdout, 1<<20)
w.Write(out)
w.Flush()
}