#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

// O(E log V)
template<typename T>
vector<pair<T, int>> dijkstra(vector<vector<pair<int, T>>> &g, int s){
     
  int n = g.size();
  // numeric_limits がうまく使えない場合は自分で INF を定義する.
  const auto inf = numeric_limits<T>::max();
  vector<pair<T, int>> dist(n, {inf, -1});

  using P = pair<T, int>;
  // 小さい順に取り出せる
  priority_queue<P, vector<P>, greater<P>> que;
  dist[s] = {0, -1};
  que.emplace(dist[s].first, s);
  while(!que.empty()){
    T cost;
    int node;
    tie(cost, node) = que.top();
    que.pop();
    if(dist[node].first < cost) continue;
    for(auto &e : g[node]){
      auto next_cost = cost + e.second;
      int next_node = e.first;
      if(dist[next_node].first <= next_cost) continue;
      dist[next_node] = {next_cost, node};
      que.emplace(next_cost, next_node);
    }
  }

  return dist;
}


long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// true だったら範囲外
bool out_of_grid(int i, int j, int h, int w) {
  return !(0 <= i and i < h and 0 <= j and j < w);
}

int main() {
 

  int h, w, k; cin >> h >> w >> k;
  int si, sj, gi, gj; cin >> si >> sj >> gi >> gj;
  si--;
  sj--;
  gi--;
  gj--;
  
  vector<vector<int>> grid(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c; cin >> c;
      if (c == '@') continue;
      grid[i][j] = 1;
    }
  }

  // ダイクストら
  using T = pair<lint, lint>;
  vector<vector<vector<T>>> dist(h, vector<vector<T>>(w, vector<T>(4, {INF, INF})));

  using P = pair<T, pair<int, pair<int, int>>>;
  // 小さい順に取り出せる
  priority_queue<P, vector<P>, greater<P>> que;
  dist[si][sj][0] = {0, k - 1};
  que.push({dist[si][sj][0], {si, {sj, 0}}});

  dist[si][sj][1] = {0, k - 1};
  que.push({dist[si][sj][1], {si, {sj, 1}}});

  dist[si][sj][2] = {0, k - 1};
  que.push({dist[si][sj][2], {si, {sj, 2}}});
  
  dist[si][sj][3] = {0, k - 1};
  que.push({dist[si][sj][3], {si, {sj, 3}}});

  while (!que.empty()) {
    T cost;
    cost = que.top().first;
    int i = que.top().second.first;
    int j = que.top().second.second.first;
    int curD = que.top().second.second.second;
    que.pop();

    if(dist[i][j][curD] < cost) continue;

    for (int dir = 0; dir < 4; dir++) {
      int ni = i + di[dir];
      int nj = j + dj[dir];
      int nD = dir;
      if (out_of_grid(ni, nj, h, w)) continue;
      if (grid[ni][nj] == 0) continue;
      T ncost;
      if (cost.second == k - 1 or curD != nD) {
        ncost = {cost.first + 1, 0};
      } else {
        ncost = {cost.first, cost.second + 1}; 
      }

      if (dist[ni][nj][nD] <= ncost) continue;
      dist[ni][nj][nD] = ncost;
      que.push({ncost, {ni, {nj, nD}}});
    }
  }

  /*
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int dir = 0; dir < 4; dir++) {
        cerr << "i = " << i << ", j = " << j << ", dir = " << dir << " : ";
        cerr << "(" << dist[i][j][dir].first << ", " << dist[i][j][dir].second << ")" << endl;
      }
    }
  }
  */

  lint ans = INF;
  for (int dir = 0; dir < 4; dir++) {
    ans = min(ans, dist[gi][gj][dir].first);
  }

  if (ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 210328