#include <vector>
#include <iostream>
using std::cout;
using std::endl;
struct range_k_wall_graph_builder {
  int N;
  int start;
  int end;
  int K;
  
  range_k_wall_graph_builder(int N, int offset, int K)

    : N(N),
      start(offset),
      end(offset + N * 2),
      K(K) {
  }

  range_k_wall_graph_builder(){}

  template<class Wall, class Idx, class Connect>
  void init(Wall wall, Idx idx, Connect con) {
    for(int i = 0; i < N; i++) {
      int v = idx(i);
      if(wall(v)) continue;
      con(start + i, v);
      con(start + N + i, v);
      if(i + 1 < N && (i + 1) % K != 0) {
        con(start + i, start + i + 1);
        con(start + N + i + 1, start + N + i);
      }
    }
  }

  template<class Wall, class Idx, class Connect>
  void build_for_right(Wall wall, Idx idx, Connect con) {
    int wi = N;
    for(int i = N; i --> 0;) {
      int v = idx(i);
      if(wall(v)) wi = i;
      else {
        con(v, start + i);
        int ni = std::min(i + K, wi - 1);
        if(i / K != ni / K) {
          con(v, start + N + ni);
        }
      }
    }
  }
  template<class Wall, class Idx, class Connect>
  void build_for_left(Wall wall, Idx idx, Connect con) {
    int wi = -1;
    for(int i = 0; i < N; i++) {
      int v = idx(i);
      if(wall(v)) wi = i;
      else {
        con(v, start + N + i);
        int ni = std::max(i - K, wi + 1);
        if(i / K != ni / K) {
          con(v, start + ni);
        }
      }
    }
  }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }



int main() {
  i64 H, W, K;
  cin >> H >> W >> K;
  i64 sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  sx--;
  sy--;
  tx--;
  ty--;
  string f = "";
  rep(i,0,H) {
    string s;
    cin >> s;
    rep(i,0,W) {
      f.push_back(s[i]);
    }
  }
  vector<vector<pair<int, bool>>> G((H * W) * 5);
  auto idx = [&](int i, int j) { return i * W + j; };
  auto wall = [&](int v) { return f[v] == '@'; };

  vector<range_k_wall_graph_builder> h_wall(H);
  vector<range_k_wall_graph_builder> w_wall(W);
  int V = H * W;
  rep(i,0,H) {
    h_wall[i] = range_k_wall_graph_builder(W, V, K);
    h_wall[i].init(wall, [&](int id) { return i * W + id; }, [&](int v, int w) { G[v].emplace_back(w, false); });
    h_wall[i].build_for_left(wall, [&](int id) { return i * W + id; }, [&](int v, int w) { G[v].emplace_back(w, true); });
    h_wall[i].build_for_right(wall, [&](int id) { return i * W + id; }, [&](int v, int w) { G[v].emplace_back(w, true); });
    V = h_wall[i].end;
  }
  rep(i,0,W) {
    w_wall[i] = range_k_wall_graph_builder(H, V, K);
    w_wall[i].init(wall, [&](int id) { return id * W + i; }, [&](int v, int w) { G[v].emplace_back(w, false); });
    w_wall[i].build_for_left(wall, [&](int id) { return id * W + i; }, [&](int v, int w) { G[v].emplace_back(w, true); });
    w_wall[i].build_for_right(wall, [&](int id) { return id * W + i; }, [&](int v, int w) { G[v].emplace_back(w, true); });
    V = w_wall[i].end;
  }

  deque<pair<int, int>> que;
  vector<i64> dist(H * W * 5, -1);
  dist[idx(sx, sy)] = 0;
  que.emplace_back(0, idx(sx, sy));

  while(!que.empty()) {
    i64 d = que.front().first;
    i64 v = que.front().second;
    que.pop_front();
    if(d > dist[v]) continue;
    for(auto e: G[v]) {
      i64 t = e.first;
      bool cost = e.second;
      if(dist[t] == -1 || dist[t] > dist[v] + cost) {
        dist[t] = dist[v] + cost;
        if(cost) {
          que.emplace_back(dist[t], t);
        }
        else {
          que.emplace_front(dist[t], t);
        }
      }
    }
  }
  i64 ans = dist[idx(tx, ty)];
  cout << ans << endl;
}



Measured memory_bytes: 378248