#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define N 200001

ll n,m;


ll get(ll x, ll y, ll id)
{
    return id*n*m + x*m + y;
}

int main()
{
  FAST/**/
   
   vector<pair<ll,ll>> moves;
   moves.pb(mp(0,1));
   moves.pb(mp(0,-1));
   moves.pb(mp(1,0));
   moves.pb(mp(-1,0));   
   
   vector<ll> dir;
   rep(4)
        dir.pb(i);
   
   ll k;
   cin>>n>>m>>k;
   
   ll x1,y1,x2,y2;
   cin>>x1>>y1>>x2>>y2;
   x1--,y1--,x2--,y2--;
   
   string arr[n];
   rep(n)
        cin>>arr[i];
   
   if(arr[x1][y1] == '@' || arr[x2][y2] == '@')
   {
       cout<<-1;
       return 0;
   }
   
   set<pair<pair<ll,ll>,ll>> st;
   
   pair<ll,ll> mdis[n][m][4];
   rep(n)
        repi(j,m)
            repi(i1,4)
                mdis[i][j][i1] = mp(inf,inf);
                
   bool vis[n][m][4];
   memset(vis,0,sizeof(vis));
   
   rep(4)
        st.insert(mp(mp(0ll,0ll),get(x1,y1,i))), mdis[x1][y1][i] = mp(0ll,0ll);
   
   while(!st.empty())
   {
       auto curr = *st.begin();
       st.erase(st.begin());
       
       ll x = ((curr.ss)%(n*m))/m;
       ll y = (((curr.ss)%(n*m))%m);
       ll id = ((curr.ss)/(n*m));
       //cout<<x+1<<" "<<y+1<<" "<<id<<" "<<curr.ss<<"\n";
       vis[x][y][id] = 1;
       
       repi(j,4)
       {
           ll x11 = (x+moves[j].ff);
           ll y11 = (y+moves[j].ss);
           
           ll i = dir[j];
           
           if(x11<0 || y11<0 || x11>=n || y11>=m)
                continue;
           
           if(arr[x11][y11] == '@')
                continue;
           if(vis[x11][y11][i])
                continue;
           pair<ll,ll> d1 = curr.ff;
           if(id!=i)
           {
               if(d1.ss != 0)
                    d1 = mp(d1.ff+1,1ll); 
               else d1 = mp(d1.ff, 1ll);        
           }
           
           else
           {
               if(d1.ss == k)
                    d1 = mp(d1.ff+1,1ll);
               else d1.ss++;        
           }
           
           if(mdis[x11][y11][i]<=d1)
                continue;
           if(mdis[x11][y11][i]!=mp((ll)inf,(ll)inf) && st.find(mp(mdis[x11][y11][i],get(x11,y11,i)))!=st.end())
           {
                st.erase(mp(mdis[x11][y11][i],get(x11,y11,i)));
                st.insert(mp(d1,get(x11,y11,i)));   
                mdis[x11][y11][i] = d1;
           }
           
           else
           {
                st.insert(mp(d1,get(x11,y11,i)));   
                mdis[x11][y11][i] = d1;
           }
       }
   }
   
   ll ans = inf;
   rep(4)
        if(vis[x2][y2][i])
            ans = min(ans,mdis[x2][y2][i].ff + (mdis[x2][y2][i].ss>0));
   
   if(ans<inf)
        cout<<ans;
   else cout<<-1;        
   
           
           
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 83932