open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

open InputUtility

module AGC015 =
    let ``Nuske vs Phantom Thnook`` () =
        let n, m = Read2Int ()
        let q = ReadNextInt ()
        let s = ReadList n
        let ga () = Array2D.zeroCreate (n + 1) (m + 1)
        let getV b i j = Array2D.get b i j
        let getS b i j = getV b (i - 1) j + getV b i (j - 1) - getV b (i - 1) (j - 1)
        let getSq b i1 j1 i2 j2 =
            getV b i2 j2 - getV b (i1 - 1) j2 - getV b i2 (j1 - 1) + getV b (i1 - 1) (j1 - 1)
        let setS b i j d = Array2D.set b i j (d + getS b i j)
        let isBlue ci cj b = if ci > 0 && cj > 0 && s.[ci - 1].[cj - 1] = '1' then b else 0
        let blues, up, left = ga (), ga (), ga ()
        for i in [1..n] do
            for j in [1..m] do
                let b = isBlue i j 1
                setS blues i j b
                isBlue (i - 1) j b |> setS up i j
                isBlue i (j - 1) b |> setS left i j
        //let out name b =
        //    printfn "%s:" name
        //    for i in [1..n] do
        //        for j in [1..m] do
        //            getV b i j |> printf "%d "
        //        printfn ""
        //out "blues" blues; out "up" up; out "left" left
        for _ in [1..q] do
            let x1, y1 = Read2Int ()
            let x2, y2 = Read2Int ()
            let gs b dx dy = getSq b (x1 + dx) (y1 + dy) x2 y2
            let cn, ce = gs blues 0 0, gs up 1 0 + gs left 0 1
            //printfn "cn = %d, ce = %d" cn ce
            cn - ce |> printfn "%d"

    let Entry = ``Nuske vs Phantom Thnook``

AGC015.Entry ()