#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define ALL(x) (int)x.size()
#define SZ(x) (int)x.size()
#define forn(i,a,b) for(int i = a; i<b; i++)
#define mset(a,v) memset(a,v,sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#ifdef D
#define debug(x) cout << x
#else
#define debug(x) //nothing
#endif
struct Point{
ll x;
ll y;
};
bool operator<(const Point &a, const Point &b){
if(a.x<b.x) return true;
if(a.x>b.x) return false;
return a.y<b.y;
}
ll r,c,n;
Point s;
Point g;
vector<string> grid;
vector<vector<bool>> vis;
vector<vector<Point>> anc;
set<Point> dispOcupa;
set<Point> dispVacio;
/* IDEA */
/*
Mantener una lista de elementos adyacentes no visitados
1) Expandir los adyacentes no visitados que sean vacios
2) Expandir los adyacentes no visitados que resten ( no vacios )
y asi hasta completar de visitar todo
*/
vector<Point> oper = {{0,1},{0,-1},{1,0},{-1,0}};
void bfs(ll type){
deque<pair<Point,Point>> cola;
if(type==0){
while(!dispVacio.empty()){
Point p = *dispVacio.begin();
cola.pb({ p, p });
dispVacio.erase(dispVacio.begin());
}
}else{
while(!dispOcupa.empty()){
Point p = *dispOcupa.begin();
cola.pb({ p, p });
dispOcupa.erase(dispOcupa.begin());
}
}
while(!cola.empty()){
Point p = cola.front().fst;
Point ancp = cola.front().snd;
cola.pop_front();
debug("Nuevo punto "<<p.x<<" "<<p.y<<" "<<ancp.x<<" "<<ancp.y<<'\n');
if(grid[p.x][p.y]=='.'){
auto it = dispVacio.find(p);
if(it!=dispVacio.end()) dispVacio.erase(it);
}else{
auto it = dispOcupa.find(p);
if(it!=dispOcupa.end()) dispOcupa.erase(it);
}
if(vis[p.x][p.y]) continue;
vis[p.x][p.y]=true;
anc[p.x][p.y]=ancp;
//debug("eliminacion realizada\n");
for(auto o:oper){
if(!(p.x+o.x>=0 && p.x+o.x<r)) continue;
if(!(p.y+o.y>=0 && p.y+o.y<c)) continue;
bool yes = true;
if(abs(ancp.x-(p.x+o.x))>=n) yes=false;
if(abs(ancp.y-(p.y+o.y))>=n) yes=false;
if(type==0){
if(anc[p.x+o.x][p.y+o.y].x==-1){
//debug("Descubrimos "<<p.x+o.x<<" "<<p.y+o.y<<'\n');
if(grid[p.x+o.x][p.y+o.y]=='.'){
dispVacio.insert({p.x+o.x, p.y+o.y});
cola.push_back({{p.x+o.x, p.y+o.y},ancp});
}else{
dispOcupa.insert({p.x+o.x, p.y+o.y});
}
}
}else{
if(anc[p.x+o.x][p.y+o.y].x==-1){
if(grid[p.x+o.x][p.y+o.y]=='#'){
dispOcupa.insert({p.x+o.x, p.y+o.y});
}else dispVacio.insert({p.x+o.x, p.y+o.y});
//debug("Descubrimos "<<p.x+o.x<<" "<<p.y+o.y<<'\n');
if(yes){
cola.push_back({{p.x+o.x, p.y+o.y},ancp});
}
}
}
}
}
}
int main(){
cin>>r>>c>>n;
cin>>s.x>>s.y; s.x--; s.y--;
cin>>g.x>>g.y; g.x--; g.y--;
grid.clear();
grid.resize(r);
vis.clear();
vis.resize(r,vector<bool>(c,false));
forn(i,0,r) cin>>grid[i];
dispVacio.insert(s);
anc.clear();
anc.resize(r);
forn(i,0,r){
anc[i].clear();
anc[i].resize(c,{-1,-1});
}
anc[s.x][s.y]=s;
bfs(0);
ll res = 0;
debug(anc[g.x][g.y].x<<" "<<anc[g.x][g.y].y<<'\n');
while(anc[g.x][g.y].x==-1){
debug("Exploracion\n");
bfs(0);
bfs(1);
bfs(0);
//ll aux = 0; cin>>aux;
res++;
}
cout<<res<<'\n';
return 0;
}