open Printf
open Scanf

let () =
  let n, m, q = scanf "%d %d %d\n" (fun x y z -> (x, y, z)) in
  let grid = Array.init n (fun _ -> let x = scanf "%s\n" (fun y -> y) in x) in
  let rec loop i =
    if i = q then ()
    else
      begin
        let x1, y1, x2, y2 = scanf "%d %d %d %d\n" (fun w x y z -> (w-1, x-1, y-1, z-1)) in
        let ar = Array.init (x2 - x1 + 1) (fun i ->
                                           Array.init (y2 - y1 + 1) (fun j -> grid.(x1+i).[y1+j])) in
        let rec remove (i, j) =
          if i >= 0 && j >= 0 && i <= x2 - x1 && j <= y2 - y1 && ar.(i).(j) = '1' then
            begin
              ar.(i).(j) <- '0';
              List.iter remove [(i-1,j);(i+1,j);(i,j-1);(i,j+1)]
            end
          else () in
        let rec count (i, j) c =
          if i = x2 - x1 + 1 then c
          else
            if j = y2 - y1 + 1 then count (i+1, 0) c
            else
              begin
                if ar.(i).(j) = '1' then
                  begin
                    remove (i,j);
                    count (i, j+1) (c+1)
                  end
                else
                  count (i, j+1) c
              end
        in
        count (0,0) 0 |> printf "%d\n";
        loop (i+1)
      end
  in
  loop 0
