//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int n,m;
bool good(pii x)
{
    if(x.st>=1&&x.st<=n&&x.nd>=1&&x.nd<=m)
        return 1;
    return 0;
}
int32_t main()
{
    speed
    int k;
    cin>>n>>m>>k;
    char T[n+2][m+2];
    int D[n+2][m+2];
    set<int> R[n+2],C[m+2];
    pii s,e;
    cin>>s.st>>s.nd>>e.st>>e.nd;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>T[i][j],D[i][j]=inf,R[i].insert(j);
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            C[i].insert(j);
    queue<pii> Q;
    D[s.st][s.nd]=0;
    R[s.st].erase(s.nd);
    C[s.nd].erase(s.st);
    Q.push(s);
    while(!Q.empty())
    {
        pii u=Q.front();
      //  cout<<u.st<<" "<<u.nd<<" "<<D[u.st][u.nd]<<endl;
        Q.pop();
        auto it1=R[u.st].upper_bound(u.nd);
        while(it1!=R[u.st].end())
        {
            int x=*it1;
            if(T[u.st][x]=='@')
                break;
            if(x-u.nd>k)
                break;
            it1++;
            D[u.st][x]=D[u.st][u.nd]+1;
            Q.push(mp(u.st,x));
            R[u.st].erase(x);
            C[x].erase(u.st);
        }
        /////////////
        auto it2=R[u.st].lower_bound(u.nd);
        bool jak=0;
        if(it2!=R[u.st].begin())
            it2--;
        else
            jak=1;
        while(!jak)
        {
            int x=*it2;
           // cout<<x<<" "<<T[u.st][x]<<endl;
            if(T[u.st][x]=='@')
                break;
            if(u.nd-x>k)
                break;
            D[u.st][x]=D[u.st][u.nd]+1;
            Q.push(mp(u.st,x));
            bool czy=0;
            if(it2!=R[u.st].begin())
                it2--;
            else
                czy=1;
            R[u.st].erase(x);
            C[x].erase(u.st);
            if(czy)
                break;
        }
        ////////////////////
        auto it3=C[u.nd].upper_bound(u.st);
        while(it3!=C[u.nd].end())
        {
            int x=*it3;
            if(T[x][u.nd]=='@')
                break;
            if(x-u.st>k)
                break;
            it3++;
            D[x][u.nd]=D[u.st][u.nd]+1;
            Q.push(mp(x,u.nd));
            C[u.nd].erase(x);
            R[x].erase(u.nd);
        }
        /////////////
        auto it4=C[u.nd].lower_bound(u.st);
        jak=0;
        if(it4!=C[u.nd].begin())
            it4--;
        else
            jak=1;
        while(!jak)
        {
            int x=*it4;
            if(T[x][u.nd]=='@')
                break;
            if(u.st-x>k)
                break;
            D[x][u.nd]=D[u.st][u.nd]+1;
            Q.push(mp(x,u.nd));
            bool czy=0;
            if(it4!=C[u.nd].begin())
                it4--;
            else
                czy=1;
            C[u.nd].erase(x);
            R[x].erase(u.nd);
            if(czy)
                break;
        }
    }
    int wynik=D[e.st][e.nd];
    if(wynik==inf)
        cout<<-1;
    else
        cout<<wynik;
    return 0;
}


Measured memory_bytes: 149192