#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
map<pll,ll>d;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
    ll h,w,k;
    cin>>h>>w>>k;
    string a[h];
    ost r[h];
    ost c[w];
    pll s,e;
    cin>>s.first>>s.second>>e.first>>e.second;
    s.first--;
    s.second--;
    e.first--;
    e.second--;
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            r[i].insert(j);
            c[j].insert(i);
        }
    }
    for(ll i=0;i<h;i++)
    {
        cin>>a[i];
    }
    set<pair<ll,pll>>st;
    st.insert({0LL,s});
    r[s.first].erase(s.second);
    c[s.second].erase(s.first);
    while(!st.empty())
    {
        pair<ll,pll> top = *st.begin();
        st.erase(top);
        //cerr<<top.first<<" "<<top.second.first<<" "<<top.second.second<<endl;
        pll co=top.second;
        d[co]=top.first;
        set<ll>delr; 
        //for row
        ll lst=max(0LL,co.second);
        //strictly less elemets
        ll ind =r[co.first].order_of_key(lst);
        ind--;
        while( ind >=0 && ind<r[co.first].size()    && (*r[co.first].find_by_order(ind))>=co.second-k && (*r[co.first].find_by_order(ind))<=co.second+k)
        {
            ll cory=*r[co.first].find_by_order(ind);
            if(a[co.first][cory]=='@')
                break;
            delr.insert(*r[co.first].find_by_order(ind));
            --ind;
        }

        ind =r[co.first].order_of_key(lst);
        while( ind<r[co.first].size()    && (*r[co.first].find_by_order(ind))>=co.second-k && (*r[co.first].find_by_order(ind))<=co.second+k)
        {
            ll cory=*r[co.first].find_by_order(ind);
            if(a[co.first][cory]=='@')
                break;
            delr.insert(*r[co.first].find_by_order(ind));
            ++ind;
        }
        for(ll x:delr)
        {
            r[co.first].erase(x);
            c[x].erase(co.first);
            st.insert({top.first+1,make_pair(co.first,x)});
        }

        set<ll>delc; 
        //for col
        lst=max(0LL,co.first);
        //strictly less elemets
        ind=c[co.second].order_of_key(lst);
        ind--;
        //cout<<ind<<endl;
        while(ind>=0 && ind<c[co.second].size()  &&  (*c[co.second].find_by_order(ind))<=co.first+k && (*c[co.second].find_by_order(ind))>=co.first-k )
        {
            ll corx=*c[co.second].find_by_order(ind);
            if(a[corx][co.second]=='@')
            {
                break;
            }
            // cout<<corx<<" "<<co.second<<endl;
            delc.insert(*c[co.second].find_by_order(ind));
            --ind;
        }
        ind=c[co.second].order_of_key(lst);
        while( ind<c[co.second].size()  &&  (*c[co.second].find_by_order(ind))<=co.first+k && (*c[co.second].find_by_order(ind))>=co.first-k)
        {
             ll corx=*c[co.second].find_by_order(ind);
            if(a[corx][co.second]=='@')
                break;
            delc.insert(*c[co.second].find_by_order(ind));
            ++ind;
        }
        for(ll x:delc)
        {
            c[co.second].erase(x);
            r[x].erase(co.second);
            st.insert({top.first+1,make_pair(x,co.second)});
            // cout<<top.first+1<<" "<<x<<" "<<co.second<<endl;
        }
    }
    if(d.find(e)==d.end())
    {
        cout<<-1LL<<endl;
    }
    else
    {
        cout<<d[e]<<endl;
    }
    return 0;
}

Measured memory_bytes: 223040