#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 239;   int n, m, k;   vector<set<int>> row;   vector<set<int>> column;   vector<set<int>> row_free;   vector<set<int>> column_free;   int get_row_left(int i, int to, int from) {     auto it = row[i].lower_bound(from);     if (it == row[i].begin()) {       return to;     }     it--;     if (to <= *(it) && *(it) <= from) {       return *(it) + 1;     } else {       return to;     }   }   int get_row_right(int i, int to, int from) {     auto it = row[i].lower_bound(from);     if (it == row[i].end()) {       return to;     }     if ((*it) <= to) {       return (*it) - 1;     } else {       return to;     }   }   int get_column_up(int j, int to, int from) {     auto it = column[j].lower_bound(from);     if (it == column[j].begin()) {       return to;     }     it--;     if (to <= *(it) && *(it) <= from) {       return *(it) + 1;     } else {       return to;     }   }   int get_column_down(int j, int to, int from) {     auto it = column[j].lower_bound(from);     if (it == column[j].end()) {       return to;     }     if ((*it) <= to) {       return (*it) - 1;     } else {       return to;     }   }   vector<pair<int, int>> all_next(int i, int j) {     int ff = get_row_left(i, max(0, j - k), j);     int ss = get_row_right(i, min(m - 1, j + k), j);     int tt = get_column_up(j, max(0, i - k), i);     int th = get_column_down(j, min(n - 1, i + k), i);     vector<pair<int, int>> ans;     if (j > 0) {       auto it = row_free[i].lower_bound(ff);       while (true) {         if (it == row_free[i].end()) {           break;         }         if (*(it) >= j) {           break;         }         ans.push_back({i, *(it)});         it++;       }     }     if (j + 1 < m) {       auto it = row_free[i].upper_bound(j);       while (true) {         if (it == row_free[i].end()) {           break;         }         if (*(it) > ss) {           break;         }         ans.push_back({i, *(it)});         it++;       }     }     if (i > 0) {       auto it = column_free[j].lower_bound(tt);       while (true) {         if (it == column_free[j].end()) {           break;         }         if (*(it) >= i) {           break;         }         ans.push_back({*(it), j});         it++;       }     }     if (i + 1 < n) {       auto it = column_free[j].upper_bound(i);       while (true) {         if (it == column_free[j].end()) {           break;         }         if (*(it) > th) {           break;         }         ans.push_back({*(it), j});         it++;       }     }     return ans;   }   void bfs(int si, int sj, int ei, int ej) {     vector<vector<int>> d(n, vector<int>(m, inf));     d[si][sj] = 0;     queue<pair<int, int>> q;     q.push({si, sj});     row_free[si].erase(sj);     column_free[sj].erase(si);     while (!q.empty()) {       auto tmp = q.front();       q.pop();       int ci = tmp.first;       int cj = tmp.second;       auto next = all_next(ci, cj);       for (auto [ni, nj] : next) {         if (d[ni][nj] > d[ci][cj] + 1) {           d[ni][nj] = d[ci][cj] + 1;           row_free[ni].erase(nj);           column_free[nj].erase(ni);           q.push({ni, nj});         }       }     }     int res = d[ei][ej];     if (res == inf) {       cout << -1;     } else {       cout << res;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     row.resize(n);     column.resize(m);     row_free.resize(n);     column_free.resize(m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char c;         cin >> c;         if (c ==  # ) {           row[i].insert(j);           column[j].insert(i);         } else {           row_free[i].insert(j);           column_free[j].insert(i);         }       }     }     int si, sj, ei, ej;     cin >> si >> sj >> ei >> ej;     si--;     sj--;     ei--;     ej--;     bfs(si, sj, ei, ej);   }