Scanf.scanf "%d %d" (fun h w ->
    let a = Array.init h (fun _ ->
        Array.init w (fun _ ->
            Scanf.scanf " %d" (fun a -> a)))
    in
    let rec loop y x dir hist =
        if y = h then hist else
            if a.(y).(x) mod 2 = 0 then (
                let x = x + dir in
                if x < 0 || x >= w then loop (y + 1) (x - dir) (-dir) hist
                                   else loop y x dir hist
            ) else (
                let nx = x + dir in
                let nx, ny, dir = if nx < 0 || nx >= w then nx - dir, y + 1, -dir
                                                       else nx, y, dir
                in
                if ny = h then hist else (
                    let hist = (y + 1, x + 1, ny + 1, nx + 1) :: hist in
                    a.(y).(x) <- a.(y).(x) - 1;
                    a.(ny).(nx) <- a.(ny).(nx) + 1;
                    loop ny nx dir hist
                )
            )
    in
    let hist = loop 0 0 1 [] in
    let l = List.length hist in
    let hist = List.rev hist in
    Printf.printf "%d\n" l;
    List.iter (fun (y, x, ny, nx) -> Printf.printf "%d %d %d %d\n" y x ny nx) hist
)