#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <unistd.h>
#include <vector>
using namespace std;
using pi = pair<int, int>;
vector<int> *baseRows;
vector<int> *baseColumns;
vector<int> *copyRows;
vector<int> *copyColumns;
constexpr int NOT_FOUND = 10000;
void findPath(int **path, int depth, pi pos, bool row, pi target, int *min) {
path[pos.first][pos.second] = depth;
int whenExact = depth - 1;
if (whenExact >= *min) return;
if (pos.first == target.first && pos.second == target.second) {
*min = whenExact;
return;
}
if (depth >= *min) return;
if (pos.first == target.first || pos.second == target.second) {
*min = depth;
return;
}
if (depth + 1 >= *min) return;
vector<int> list = row ? baseRows[pos.second] : baseColumns[pos.first];
if (list.empty()) return;
for (int i : list) {
pi pos2;
if (row) pos2 = { i, pos.second };
else pos2 = { pos.first, i };
int found = path[pos2.first][pos2.second];
if (found <= depth + 1) continue;
findPath(path, depth + 1, pos2, !row, target, min);
}
}
int main(int argc, char *argv[]) {
int height, width, count; cin >> height >> width >> count;
baseRows = new vector<int>[height];
baseColumns = new vector<int>[width];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
char c; cin >> c;
if (c == '.') {
baseRows[y].push_back(x);
baseColumns[x].push_back(y);
}
}
}
vector<pair<pi, pi>> queries;
for (int i = 0; i < count; i++) {
int y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2;
queries.push_back({ { x1 - 1, y1 - 1 }, { x2 - 1, y2 - 1 } });
}
int **path = new int*[width];
for (int i = 0; i < width; i++) {
int *arr = new int[height];
path[i] = arr;
}
auto startTime = chrono::high_resolution_clock::now();
for (auto [start, end] : queries) {
int min = NOT_FOUND;
for (int i = 0; i < width; i++)
memset((void*)(path[i]), 127, height * sizeof(int));
for (int i = 0; i < height; i++)
sort(baseRows[i].begin(), baseRows[i].end(), [end](int p1, int p2) -> bool { return abs(p1 - end.first) < abs(p2 - end.first); });
for (int i = 0; i < width; i++)
sort(baseColumns[i].begin(), baseColumns[i].end(), [end](int p1, int p2) -> bool { return abs(p1 - end.second) < abs(p2 - end.second); });
findPath(path, 1, start, true, end, &min);
findPath(path, 1, start, false, end, &min);
if (min == NOT_FOUND) min = -1;
cout << min << endl;
}
auto endTime = chrono::high_resolution_clock::now();
cout << endTime - startTime << endl;
}