program nuske_vs_phantom_thnook
  implicit none
  integer :: n, m, q, a(0:2000,0:2000), x1, y1, x2, y2, i, j, k
  integer :: x(0:2000,0:2000), y(0:2000,0:2000), z(0:2000,0:2000)
  character(2000) :: s
  a = 0
  x = 0
  y = 0
  z = 0
  read(*,*) n, m, q
  do i = 1, n
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, m
      if (s(j:j).eq."1") a(i,j) = 1
    end do
  end do
  do i = 1, n
    do j = 1, m
      x(i,j) = x(i,j-1)+x(i-1,j)-x(i-1,j-1)+a(i,j)
      y(i,j) = y(i,j-1)+y(i-1,j)-y(i-1,j-1)+a(i,j)*a(i,j-1)
      z(i,j) = z(i,j-1)+z(i-1,j)-z(i-1,j-1)+a(i,j)*a(i-1,j)
    end do
  end do
  do k = 1, q
    read(*,*) x1, y1, x2, y2
    write(*,'(i0)') f(x,x1,y1,x2,y2)-f(y,x1,y1+1,x2,y2)-f(z,x1+1,y1,x2,y2)
  end do
  stop
contains
  integer function f(x,i1,j1,i2,j2)
    implicit none
    integer, intent(in) :: x(0:2000,0:2000), i1, j1, i2, j2
    f = x(i2,j2)-x(i2,j1-1)-x(i1-1,j2)+x(i1-1,j1-1)
    return
  end function f
end program nuske_vs_phantom_thnook