#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int n, m, k;
vector<set<int>> row, col;
vector<vector<char>> grid;
vector<vi> rowPr, colPr;
int sum(vi& v1, int s, int e) {
	int ret = v1[e];
	if (s)
		ret -= v1[s - 1];
	return ret;
}
int mx(set<int> &v1, vi &pre, int val) {
	auto it = v1.upper_bound(val);
	if (it == v1.end())
		return -1;
	if (abs(val - *it) > k || sum(pre, val, *it)) return -1;
	int ret = *it;
	v1.erase(it);
	return ret;
}
int mn(set<int>& v1, vi&pre, int val) {
	if (v1.empty())
		return -1;
	auto it = v1.lower_bound(val);
	if (it == v1.begin())
		return -1;
	it--;
	if (abs(val - *it) > k || sum(pre, *it, val)) return -1;
	int ret = *it;
	v1.erase(it);
	return ret;
}

int main() {
	//file();
	fast();
	cin >> n >> m >> k;
	int s1, s2, e1, e2;
	cin >> s1 >> s2 >> e1 >> e2;
	s1--, s2--, e1--, e2--;
	grid = vector<vector<char>>(n, vector<char>(m));
	row = vector<set<int>>(n), col = vector<set<int>>(m);
	rowPr = vector<vi>(n), colPr = vector<vi>(m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> grid[i][j];
	for (int i = 0; i < n; i++) {
		vi tmp;
		int cnt = 0;
		for (int j = 0; j < m; j++) {
			if (grid[i][j] == '.')
				row[i].insert(j);
			cnt += (grid[i][j] == '@' ? 1 : 0);
			tmp.push_back(cnt);
		}
		rowPr[i] = tmp;
	}
	for (int j = 0; j < m; j++) {
		vi tmp; 
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (grid[i][j] == '.')
				col[j].insert(i);
			cnt += (grid[i][j] == '@' ? 1 : 0);
			tmp.push_back(cnt);
		}
		colPr[j] = tmp;
	}
	if (grid[s1][s2] != '.' || grid[e1][e2] != '.')
		RT("-1\n");
	queue<pair<ii, int>> q;
	// erase s1, s2
	q.push({ {s1, s2}, 0 });
	row[s1].erase(row[s1].lower_bound(s2));
	col[s2].erase(col[s2].lower_bound(s1));
	int ans = -1;
	while (!q.empty()) {
		ii cur = q.front().first; int dep = q.front().second;
		q.pop();
		if (cur == make_pair(e1, e2)) {
			ans = dep;
			break;
		}
		// go right
		int x = cur.first, y = cur.second;
		int hold = mx(row[x], rowPr[x], y);
		while (hold != -1) {
			q.push({ { x, hold }, dep + 1 });
			hold = mx(row[x], rowPr[x], y);
		}
		// go left
		hold = mn(row[x], rowPr[x], y);
		while (hold != -1) {
			q.push({ {x, hold}, dep + 1 });
			hold = mn(row[x], rowPr[x], y);
		}
		// go up
		hold = mn(col[y], colPr[y], x);
		while (hold != -1) {
			q.push({ { hold, y }, dep + 1 });
			hold = mn(col[y], colPr[y], x);
		}
		// go down
		hold = mx(col[y], colPr[y], x);
		while (hold != -1) {
			q.push({{ hold, y }, dep + 1});
			hold = mx(col[y], colPr[y], x);
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 203016