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

const long long INF = 1001001001001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H, W; long long K; cin >> H >> W >> K;
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;

	vector<vector<char>> c(H, vector<char>(W));
	for(int i=0; i<H; ++i) {
	    for(int j=0; j<W; ++j) cin >> c[i][j];
	}

	vector<vector<vector<long long>>> dist(H, vector<vector<long long>>(W, vector<long long>(4, INF)));
	for(int i=0; i<4; ++i) dist[x1][y1][i] = 0;

	using tup = tuple<long long, int, int, int>;
	priority_queue<tup, vector<tup>, greater<tup>> Q;
	for(int i=0; i<4; ++i) Q.emplace(0, x1, y1, i);
	while(!Q.empty()) {
	    auto [cost, x, y, d] = Q.top(); Q.pop();
		if(dist[x][y][d] < cost) continue;

		int nx = x + dx[d], ny = y + dy[d];
		if(nx >= 0 && nx < H && ny >= 0 && ny < W &&
		   c[nx][ny] == '.' && dist[nx][ny][d] > cost + 1) {
		    dist[nx][ny][d] = cost + 1;
			Q.emplace(dist[nx][ny][d], nx, ny, d);
		}

		for(int i=0; i<4; ++i) {
			long long ncost = (cost + K - 1) / K * K;
			if(dist[x][y][i] > ncost) {
			    dist[x][y][i] = ncost;
				Q.emplace(dist[x][y][i], x, y, i);
			}
		}
	}

	long long res = INF;
	for(int i=0; i<4; ++i) {
	    if(dist[x2][y2][i] == INF) continue;
	    res = min(res, (dist[x2][y2][i] + K - 1) / K);
	}
	cout << (res == INF ? -1 : res) << '\n';
}
