{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Control.Monad.Primitive
import Control.Monad.ST
import qualified Data.ByteString.Char8 as C
import Data.Char
import qualified Data.Set as S
import Data.Ix
import Data.List
import Data.Maybe
import Data.STRef
import Data.Vector.Generic ((!))
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

main = sol <$> get <*> get <*> getT >>= print

get = unfoldr (C.readInt . C.dropWhile (<'0')) <$> C.getLine

getT = U.unfoldr C.uncons . C.filter (not . isSpace) <$> C.getContents

sol [h,w,k] [x1,y1,x2,y2] tbl = fromMaybe (-1) $ runST $ do
  let
    p1 = (x1,y1)
    p2 = (x2,y2)
    loop i t s = do
      skin <- readSTRef s
      if S.null skin
        then return Nothing
        else if p2 `S.member` skin
          then return $ Just i
          else do
            let ps = S.toList skin
            mapM_ (flip (UM.unsafeWrite t) 'X' . ix) ps
            foldM (unt t) S.empty ps >>= writeSTRef s
            loop (i+1) t s
    nbr t (x,y) = fmap (S.fromList . foldr1 (++)) 
      $ mapM (takeWhileM (ok t) . takeWhile ir) [
      [(x+j,y) | j <- [1..k]],[(x-j,y) | j <- [1..k]],
      [(x,y+j) | j <- [1..k]],[(x,y-j) | j <- [1..k]]]
    unt t b = liftM (S.union b) . nbr t
    ok t p = fmap (=='.') $ UM.unsafeRead t (ix p)
    ir (x,y) = inRange (1,h) x && inRange (1,w) y
    ix (r,c) = (r-1)*w+c-1
  t <- U.unsafeThaw tbl
  s <- newSTRef (S.singleton p1)
  loop (0 :: Int) t s

-- from Contol.Monad.ListM (monadlist-0.0.2)
takeWhileM :: (Monad m, MonadPlus p) => (a -> m Bool) -> [a] -> m (p a)
takeWhileM _ [] = return mzero
takeWhileM p (x:xs) = do
  bool <- p x
  if bool
    then liftM (consM x) $ takeWhileM p xs
    else return mzero

consM :: (MonadPlus p) => a -> p a -> p a
consM x y = return x `mplus` y