#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > Dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W, K, x1, y1, x2, y2;
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;
    vector<string> c(H);
    REP(i, H) cin >> c[i];

    const ll INF = (1ll<<60);
    vector<pll> dist(H*W*4, {INF, INF});
    auto tup2num = [&](ll d, ll x, ll y){
        ll val = d*H*W + x*W + y;
        return val;
    };
    auto num2tup = [&](ll val){
        ll d = val/(H*W);
        val %= H*W;
        ll x = val/W;
        val %= W;
        ll y = val;
        tuple<ll, ll, ll> res = {d, x, y};
        return res;
    };

    using Pi = pair<pll, ll>;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    REP(i, 4){
        ll idx = tup2num(i, x1,  y1);
        dist[idx] = {0, 0};
        que.emplace(dist[idx], idx);
    }

    vl dx = {1, 0, -1, 0};
    vl dy = {0, 1, 0, -1};

    while(!que.empty()) {
        pll cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        auto [d, x, y] = num2tup(idx);
        auto c1 = cost.first;
        auto c2 = cost.second;

        // dump(d)
        // dump(x)
        // dump(y)
        // dump(cost)
        // cout << endl;

        REP(dir, 4){
            ll nx = x + dx[dir];
            ll ny = y + dy[dir];
            if(nx<0 or ny<0 or nx>=H or ny>=W) continue;
            if(c[nx][ny] == '@') continue;

            ll nd = dir;
            pll next_cost;
            if(dir == d){
                nd = d;
                if(c2==K){
                    next_cost = {c1+1, 1};
                }else{
                    next_cost = {c1, c2+1};
                }
            }else{
                next_cost = {c1+1, 1};
            }

            ll next_idx = tup2num(nd, nx, ny);
            if(dist[next_idx]<=next_cost) continue;
            dist[next_idx] = next_cost;
            que.emplace(dist[next_idx], next_idx);
        }
    }

    ll res = INF;
    REP(i, 4){
        ll gdx = tup2num(i, x2, y2);
        if(dist[gdx].first==INF) continue;
        ll D = dist[gdx].first + (dist[gdx].second != 0);
        chmin(res, D);
    }
    cout << (res==INF ? -1 : res) << endl;

    return 0;
}

Measured memory_bytes: 73224