//by szh
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define inf 0x3f3f3f3f
#define debug(x) cerr<<#x<<"="<<x<<'\n'
#define rep(i, a, b) for (int i=a; i<(b); i++)

const int maxn=1e6+10;
const int dx[4]={1,-1,0,0},dy[4]={0,0,-1,1};

int m,n,K;

int x1,Y1,x2,y2;
int s,e;
int grid[maxn],fr[maxn],fc[maxn];
int	rl[maxn],rr[maxn],cl[maxn],cr[maxn];
int dis[maxn];
int far[4][maxn];

int getfr(int x) {
	if (fr[x]==x) return x;
	else return fr[x]=getfr(fr[x]);
}

int getfc(int x) {
	if (fc[x]==x) return x;
	else return fc[x]=getfc(fc[x]);
}

void merge(int x,int y) {
	if (abs(x-y)==1) {
		int fx=getfr(x),fy=getfr(y);
		fr[fx]=fy;
		rl[fy]=min(rl[fx],rl[fy]);
		rr[fy]=max(rr[fx],rr[fy]);
	}
	else {
		int fx=getfc(x),fy=getfc(y);
		fc[fx]=fy;
		cl[fy]=min(cl[fx],cl[fy]);
		cr[fy]=max(cr[fx],cr[fy]);
	}
}

int DIS(int x,int y) {
	int x1=x/m,x2=x%m,Y1=y/m,y2=y%m;
	return abs(x1-Y1)+abs(x2-y2);
}

queue <int> q;

void del(int cur) {
	if (cur%m>0&&dis[cur-1]!=-1) merge(cur-1,cur);
	if (cur%m!=m-1&&dis[cur+1]!=-1) merge(cur,cur+1);
	if (cur/m>0&&dis[cur-m]!=-1) merge(cur-m,cur);
	if (cur/m!=n-1&&dis[cur+m]!=-1) merge(cur,cur+m);
} 

int main(){
    std::ios::sync_with_stdio(false);
    cin>>n>>m>>K>>x1>>Y1>>x2>>y2;
    x1--,Y1--,x2--,y2--;
    int s=x1*m+Y1,e=x2*m+y2;
	memset(dis,-1,sizeof(dis));
	dis[s]=0;
    rep(i,0,n)
    	rep(j,0,m) {
    		char c;
    		cin>>c;
    		int x=i*m+j;
    		rl[x]=rr[x]=cl[x]=cr[x]=fr[x]=fc[x]=x;
    		if (c=='@') {
    			grid[x]=0;
    			dis[x]=233;
    			if (j!=0&&grid[x-1]==0) merge(x-1,x);
    			if (i!=0&&grid[x-m]==0) merge(x-m,x);
    			rep(k,0,4) far[k][x]=x;
			}
			else {
				if (i==0) far[1][x]=x;
				else far[1][x]=max(far[1][x-m],x-K*m);
				if (j==0) far[2][x]=x;
				else far[2][x]=max(far[2][x-1],x-K);
    			grid[x]=1;
			}
		}
	for (int i=n-1;i>=0;i--)
		for (int j=m-1;j>=0;j--) {
			int x=i*m+j;
			if (grid[i*m+j]==1) {
				if (i==n-1) far[0][x]=x;
				else far[0][x]=min(far[0][x+m],x+K*m);
				if (j==m-1) far[3][x]=x;
				else far[3][x]=min(far[3][x+1],x+K);
			}
		}
	q.push(s);
	int cnt=0;
	while (!q.empty()) {
		int u=q.front();
		q.pop();
//		cout<<u/m<<" "<<u%m<<endl;
		cnt++;
		if (cnt>n*m*2) debug(cnt);
//		debug(dis[u]);
		if (u==e) break;
		//right
		int cur=rr[getfr(u)]+1;
		while (cur/m==u/m&&cur<=far[3][u]) {
//			debug(cur);
			if (dis[cur]==-1) {
				del(cur);
				dis[cur]=dis[u]+1;
				q.push(cur);
			}
			cur=rr[getfr(cur)]+1;
		}
		//left
		cur=rl[getfr(u)]-1;
		while (cur>=0&&cur/m==u/m&&cur>=far[2][u]) {
//			debug(cur);
			if (dis[cur]==-1) {
				del(cur);
				dis[cur]=dis[u]+1;
				q.push(cur);
			}
			cur=rl[getfr(cur)]-1;
		}
		//up
		cur=cl[getfc(u)]-m;
		while (cur>=0&&cur>=far[1][u]) {
//			debug(cur);
			if (dis[cur]==-1) {
				del(cur);
				dis[cur]=dis[u]+1;
				q.push(cur);
			}
			cur=cl[getfc(cur)]-m;
		}
		//down
		cur=cr[getfc(u)]+m;
		while (cur<n*m&&cur<=far[0][u]) {
//			debug(cur);
			if (dis[cur]==-1) {
				del(cur);
				dis[cur]=dis[u]+1;
				q.push(cur);
			}
			cur=cr[getfc(cur)]+m;
		}
	}
	cout<<dis[e];
	return 0;
}

Measured memory_bytes: 51212