// Subtasks:
// 2: AC
// 3: AC
// 4: AC
// _: WA

// Broken idea but happens to work in ST2 & ST4?

#include <iostream>
#include <vector>

using namespace std;

#define N 1000

int n, q;
string grid[N+1];

int m = 0;
int in_tree[N+1][N+1];
int depth[N*N+1];
int min_parent[N*N+1];
int max_parent[N*N+1];

int create_tree(int y, int x) {
    vector<pair<int,int>> queue;
    queue.push_back({y,x});
    m++;
    in_tree[y][x] = m;
    depth[m] = 0;
    min_parent[m] = 0;
    max_parent[m] = 0;
    int dy[4] = {0, 1, 0, -1};
    int dx[4] = {-1, 0, 1, 0};
    for (int i = 0; i < queue.size(); i++) {
        int cy = queue[i].first;
        int cx = queue[i].second;
        for (int j = 0; j < 4; j++) {
            int uy = cy + dy[j];
            int ux = cx + dx[j];
            if (grid[uy][ux] == '#') {
                if (!in_tree[uy][ux]) {
                    m++;
                    in_tree[uy][ux] = m;
                    depth[m] = depth[in_tree[cy][cx]] + 1;
                    min_parent[m] = in_tree[cy][cx];
                    max_parent[m] = in_tree[cy][cx];
                    queue.push_back({uy, ux});
                } else if (depth[in_tree[uy][ux]] == depth[in_tree[cy][cx]] + 1) {
                    min_parent[in_tree[uy][ux]] =
                        min(min_parent[in_tree[uy][ux]], in_tree[cy][cx]);
                    max_parent[in_tree[uy][ux]] =
                        max(max_parent[in_tree[uy][ux]], in_tree[cy][cx]);
                }
            }
        }
    }
    return -1;
}

#define K 20
int min_jump[N*N+1][K];
int max_jump[N*N+1][K];

bool has_same(int min_p1, int max_p1, int min_p2, int max_p2) {
    if (max_p1 < min_p2) return false;
    if (max_p2 < min_p1) return false;
    return true;
}

int main() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> grid[i];
        grid[i] = '.' + grid[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (grid[i][j] == '#' && m == 0) {
                create_tree(i, j);
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        min_jump[i][0] = min_parent[i];
        max_jump[i][0] = max_parent[i];
    }
    for (int k = 1; k < K; k++) {
        for (int i = 1; i <= m; i++) {
            min_jump[i][k] = min_jump[min_jump[i][k-1]][k-1];
            max_jump[i][k] = max_jump[max_jump[i][k-1]][k-1];
        }
    }
    for (int i = 1; i <= q; i++) {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        int min_p1 = in_tree[y1][x1];
        int max_p1 = in_tree[y1][x1];
        int min_p2 = in_tree[y2][x2];
        int max_p2 = in_tree[y2][x2];
        if (depth[min_p1] < depth[min_p2]) {
            swap(min_p1, min_p2);
            swap(max_p1, max_p2);
        }
        int ans = 0;
        for (int k = K-1; k >= 0; k--) {
            if (depth[min_p1] - (1<<k) >= depth[min_p2]) {
                min_p1 = min_jump[min_p1][k];
                max_p1 = max_jump[max_p1][k];
                ans += (1<<k);
            }
        }
        if (!has_same(min_p1, max_p1, min_p2, max_p2)) {
            for (int k = K-1; k >= 0; k--) {
                if (!has_same(min_jump[min_p1][k], max_jump[max_p1][k],
                              min_jump[min_p2][k], max_jump[max_p2][k])) {
                    ans += 2 * (1<<k);
                    min_p1 = min_jump[min_p1][k];
                    max_p1 = max_jump[max_p1][k];
                    min_p2 = min_jump[min_p2][k];
                    max_p2 = max_jump[max_p2][k];
                }
            }
            ans += 2;
        }
        cout << ans << "\n";
    }
}
