//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


//std::ios::sync_with_stdio(false);
string s[1000005];
vector<set<int> > row,col;
set<int>::iterator it;
vector<vi>d,pre_row,pre_col,suf_row,suf_col;
queue<pii>q;
int main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int h,w,k,i,j,prev,r,c,r1,c1;
	pii p;
	cin>>h>>w>>k;
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	row.resize(h+5);
	col.resize(w+5);
	d.resize(h+5);
	pre_row.resize(h+5);
	suf_row.resize(h+5);
	pre_col.resize(h+5);
	suf_col.resize(h+5);
	rep(i,h){
		d[i].resize(w+5);
		pre_row[i].resize(w+5);
		suf_row[i].resize(w+5);
		pre_col[i].resize(w+5);
		suf_col[i].resize(w+5);
	}
	vi rem;
	rep(i,h){
		cin>>s[i];
		rep(j,w)
			row[i].insert(j);
	}
	rep(j,w){
		rep(i,h){
			d[i][j]=-1;
			col[j].insert(i);
		}
	}
	rep(i,h){
		prev=-1;
		rep(j,w){
			if(s[i][j]=='@'){
				prev=j;
			}
			pre_row[i][j]=prev;
			pre_row[i][j]=max(pre_row[i][j],j-k-1);
		}
	}
	rep(i,h){
		prev=w;
		fd(j,w-1,0){
			if(s[i][j]=='@'){
				prev=j;
			}
			suf_row[i][j]=prev;
			suf_row[i][j]=min(suf_row[i][j],j+k+1);
		}
	}
	rep(i,w){
		prev=-1;
		rep(j,h){
			if(s[j][i]=='@'){
				prev=j;
			}
			pre_col[j][i]=prev;
			pre_col[j][i]=max(pre_col[j][i],j-k-1);
		}
	}
	rep(i,w){
		prev=h;
		fd(j,h-1,0){
			if(s[j][i]=='@'){
				prev=j;
			}
			suf_col[j][i]=prev;
			suf_col[j][i]=min(suf_col[j][i],j+k+1);
		}
	}
	x1--;
	y1--;
	x2--;
	y2--;
	d[x1][y1]=0;
	q.push(mp(x1,y1));
	row[x1].erase(y1);
	col[y1].erase(x1);
	while(!q.empty()){
		p=q.front();
		q.pop();
		r=p.ff;
		c=p.ss;	
		it=row[r].upper_bound(c);
		while(it!=row[r].end() && *it<suf_row[r][c]){
 			c1=*it;
 			r1=r;
			q.push(mp(r1,c1));
			col[c1].erase(r1);
			d[r1][c1]=d[r][c]+1;
			rem.pb(c1);
			it++;
		}
		rep(i,rem.size()){
			row[r].erase(rem[i]);
		}
		rem.clear();

		it=row[r].upper_bound(c);
		if(it!=row[r].begin()){
			it--;
			while(*it>pre_row[r][c]){
	 			c1=*it;
	 			r1=r;
				q.push(mp(r1,c1));
				col[c1].erase(r1);
				d[r1][c1]=d[r][c]+1;
				rem.pb(c1);
				if(it==row[r].begin()){
					break;
				}
				it--;
			}
			rep(i,rem.size()){
				row[r].erase(rem[i]);
			}
			rem.clear();
		}

		it=col[c].upper_bound(r);
		while(it!=col[c].end() && *it<suf_col[r][c]){
 			r1=*it;
 			c1=c;
			q.push(mp(r1,c1));
			row[r1].erase(c1);
			d[r1][c1]=d[r][c]+1;
			rem.pb(r1);
			it++;
		}
		rep(i,rem.size()){
			col[c].erase(rem[i]);
		}
		rem.clear();
		
		it=col[c].upper_bound(r);
		if(it!=col[c].begin()){
			it--;
			while(*it>pre_col[r][c]){
	 			r1=*it;
	 			c1=c;
				q.push(mp(r1,c1));
				row[r1].erase(c1);
				d[r1][c1]=d[r][c]+1;
				rem.pb(r1);
				if(it==col[c].begin()){
					break;
				}
				it--;
			}
			rep(i,rem.size()){
				col[c].erase(rem[i]);
			}
			rem.clear();
		}
	}
	cout<<d[x2][y2]<<endl;
	return 0;
} 


Measured memory_bytes: 195656