#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e6 + 10;
vector<string> tab;
int n, m, k;
int used[MAX_N][4];

int ind(int x, int y) {
    return x * m + y;
}

int pos(int x, int y) {
    if(x == -1) {
        return 1;
    } else if(x == 1) {
        return 2;
    } else if(y == -1) {
        return 3;
    } else {
        return 4;
    }
}

struct State {
    int ind, dst, pos, charge;
    bool operator <(const State &other) const {
        if(dst == other.dst) {
            if(ind == other.ind) {
                if(pos == other.pos) {
                    return charge < other.charge;
                }
                return pos < other.pos;
            }
            return ind < other.ind;
        }
        return dst > other.dst;
    }
};

int ans = mod;

void dij(int x1, int y1, int x2, int y2) {
    priority_queue<State> pq;
    pq.push({ind(x1, y1), 0, 0, 0});
    while(!pq.empty()) {
        auto curr = pq.top(); pq.pop();
        if(curr.ind == ind(x2, y2)) {
            chkmin(ans, curr.dst);
        }
        if(used[curr.ind][curr.pos]) {continue;}
        used[curr.ind][curr.pos] = true;
        int x = curr.ind / m, y = curr.ind % m;
        //cout << x << " " << y << " " << curr.dst << endl;
        if(x > 0 && tab[x - 1][y] == '.') {
            if(pos(-1, 0) == curr.pos && curr.charge > 0) {
                pq.push({ind(x - 1, y), curr.dst, pos(-1, 0), curr.charge - 1});
            } else {
                pq.push({ind(x - 1, y), curr.dst + 1, pos(-1, 0), k - 1});
            }
        }
        if(y > 0 && tab[x][y - 1] == '.') {
            if(pos(0, -1) == curr.pos && curr.charge > 0) {
                pq.push({ind(x, y - 1), curr.dst, pos(0, -1), curr.charge - 1});
            } else {
                pq.push({ind(x, y - 1), curr.dst + 1, pos(0, -1), k - 1});
            }
        }
        if(x < n - 1 && tab[x + 1][y] == '.') {
            if(pos(1, 0) == curr.pos && curr.charge > 0) {
                pq.push({ind(x + 1, y), curr.dst, pos(1, 0), curr.charge - 1});
            } else {
                pq.push({ind(x + 1, y), curr.dst + 1, pos(1, 0), k - 1});
            }
        }
        if(y < m - 1 && tab[x][y + 1] == '.') {
            if(pos(0, 1) == curr.pos && curr.charge > 0) {
                pq.push({ind(x, y + 1), curr.dst, pos(0, 1), curr.charge - 1});
            } else {
                pq.push({ind(x, y + 1), curr.dst + 1, pos(0, 1), k - 1});
            }
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m >> k;
    tab.resize(n);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for(int i = 0; i < n; i ++) {
        cin >> tab[i];
    }
    dij(a - 1, b - 1, c - 1, d - 1);
    if(ans == mod) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 29376