#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--;
  vector<string> f(H);
  rep(i,0,H) {
    cin >> f[i];
  }
  vector<vector<pair<i64, bool>>> G((H * W) * 5);
  
  auto idx = [&](i64 i, i64 j) { return i * W + j; };
  const i64 N = H * W;
  rep(i,0,H) {
    rep(j,0,W) {
      if(f[i][j] == '@') continue;
      i64 v = idx(i, j);
      G[N + v].emplace_back(v, false);
      G[N * 2 + v].emplace_back(v, false);
      G[N * 3 + v].emplace_back(v, false);
      G[N * 4 + v].emplace_back(v, false);
      if(i + 1 < H && f[i + 1][j] == '.' && (i + 1) % K != 0) {
        i64 w = idx(i + 1, j);
        G[N + v].emplace_back(N + w, false);
        G[N * 2 + w].emplace_back(N * 2 + v, false);
      }
      if(j + 1 < W && f[i][j + 1] == '.' && (j + 1) % K != 0) {
        i64 w = idx(i, j + 1);
        G[N * 3 + v].emplace_back(N * 3 + w, false);
        G[N * 4 + w].emplace_back(N * 4 + v, false);
      }
    }
  }

  rep(i,0,H) {
    i64 a = W;
    for(i64 j = W; j --> 0;) {
      i64 v = idx(i, j);
      if(f[i][j] == '@') {
        a = j;
      }
      else {
        G[v].emplace_back(N * 3 + v, true);
        int nj = std::min(j + K, a - 1);
        if(j / K != nj / K) {
          //cout << i << " " << j << " -> " << i << " " << nj << endl;
          G[v].emplace_back(N * 4 + idx(i, nj), true);
        }
      }
    }
    a = -1;
    rep(j,0,W) {
      i64 v = idx(i, j);
      if(f[i][j] == '@') {
        a = j;
      }
      else {
        G[v].emplace_back(N * 4 + v, true);
        int nj = std::max(j - K, a + 1);
        if(j / K != nj / K) {
          //cout << i << " " << j << " -> " << i << " " << nj << endl;
          G[v].emplace_back(N * 3 + idx(i, nj), true);
        }
      }
    }
  }
  rep(j,0,W) {
    i64 a = H;
    for(i64 i = H; i --> 0;) {
      i64 v = idx(i, j);
      if(f[i][j] == '@') {
        a = i;
      }
      else {
        G[v].emplace_back(N + v, true);
        int ni = std::min(i + K, a - 1);
        if(i / K != ni / K) {
          //cout << i << " " << j << " -> " << ni << " " << j << endl;
          G[v].emplace_back(N * 2 + idx(ni, j), true);
        }
      }
    }
    a = -1;
    rep(i,0,H) {
      i64 v = idx(i, j);
      if(f[i][j] == '@') {
        a = i;
      }
      else {
        G[v].emplace_back(N * 2 + v, true);
        int ni = std::max(i - K, a + 1);
        if(i / K != ni / K) {
          //cout << i << " " << j << " -> " << ni << " " << j << endl;
          G[v].emplace_back(N + idx(ni, j), true);
        }
      }
    }
  }
  rep(i,0,H) {
    rep(j,0,W) {
      if(f[i][j] == '@') {
        i64 v = idx(i, j);
        G[v].clear();
        G[N + v].clear();
        G[N * 2 + v].clear();
        G[N * 3 + v].clear();
        G[N * 4 + v].clear();
      }
    }
  }
  deque<pair<int, int>> que;
  vector<i64> dist(H * W * 5, -1);
  dist[idx(sx, sy)] = 0;
  que.emplace_back(0, idx(sx, sy));

  auto debug = [&](i64 v) {
    i64 h = v / N;
    i64 x = (v % N) / W;
    i64 y = ((v % N) % W);
    cout << "(" << x << " " << y << " " << h << ")";
    return "";
  };

  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: 454824