#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

struct Elm {
  int r, c;
  int d1, d2;
  int dir;
};

bool operator< (Elm e1, Elm e2) {
  return tuple<int, int, int, int, int>(e1.d1, e1.d2, e1.r, e1.c, e1.dir) < tuple<int, int, int, int, int>(e2.d1, e2.d2, e2.r, e2.c, e2.dir);
}

bool operator>(Elm e1, Elm e2) {
  return !(e1 < e2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll h, w, k;
  cin >> h >> w >> k;
  P st, gl;
  cin >> st.first >> st.second;
  cin >> gl.first >> gl.second;
  st.first--;
  st.second--;
  gl.first--;
  gl.second--;
  vector<vector<bool>> g(h, vector<bool>(w));
  REP(i, h) {
    REP(j, w) {
      char c;
      cin >> c;
      g[i][j] = c == '.';
    }
  }

  priority_queue<Elm, vector<Elm>, greater<Elm>> pq;
  vector<vector<vector<P>>> d(h, vector<vector<P>>(w, vector<P>(4, {INF, INF})));
  pq.push({st.first, st.second, 0, 0, 0});
  pq.push({st.first, st.second, 0, 0, 1});
  pq.push({st.first, st.second, 0, 0, 2});
  pq.push({st.first, st.second, 0, 0, 3});

  d[st.first][st.second][0] = {0, 0};
  d[st.first][st.second][1] = {0, 0};
  d[st.first][st.second][2] = {0, 0};
  d[st.first][st.second][3] = {0, 0};

  vi dr = {0, 1, 0, -1};
  vi dc = {1, 0, -1, 0};

  while (!pq.empty()) {
    auto now = pq.top(); pq.pop();

    int nr = now.r + dr[now.dir], nc = now.c + dc[now.dir];
    if(0 <= nr && nr < h && 0 <= nc && nc < w && g[nr][nc]) {
      int nd1 = now.d1, nd2 = now.d2 + 1;
      if(nd2 == k) {
        nd1++;
        nd2 = 0;
      }

      if(d[nr][nc][now.dir] > make_pair(nd1, nd2)) {
        d[nr][nc][now.dir] = make_pair(nd1, nd2);
        pq.push({nr, nc, nd1, nd2, now.dir});
      }
    }

    int nd1 = now.d1 + (now.d2 != 0);

    if(d[now.r][now.c][(now.dir+1)%4] > make_pair(nd1, 0)) {
      d[now.r][now.c][(now.dir+1)%4] = make_pair(nd1, 0);
      pq.push({now.r, now.c, nd1, 0, (now.dir+1)%4});
    }

    if(d[now.r][now.c][(now.dir+3)%4] > make_pair(nd1, 0)) {
      d[now.r][now.c][(now.dir+3)%4] = make_pair(nd1, 0);
      pq.push({now.r, now.c, nd1, 0, (now.dir+3)%4});
    }
  }

  int ans = INF;
  REP(i, 4) {
    chmin(ans, d[gl.first][gl.second][i].first + (d[gl.first][gl.second][i].second!=0));
  }
  cout << (ans == INF ? -1 : ans) << endl;

}








Measured memory_bytes: 143872