// WA

// NOTE: Longest possible path in ST3 is around 498998 (spiral)
// K=19 is the smallest that should work

// Ratkaisussa on ongelmana, että hyppytaulukon vakio K on liian pieni.
// Kannattaa kokeilla myös suuremmilla (mutta edelleen liian pienillä) K:n arvoilla.

#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 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;
    parent[m] = 0;
    int dy[4] = {0, 0, 1, -1};
    int dx[4] = {1, -1, 0, 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] == '#' && !in_tree[uy][ux]) {
                m++;
                in_tree[uy][ux] = m;
                depth[m] = depth[in_tree[cy][cx]] + 1;
                parent[m] = in_tree[cy][cx];
                queue.push_back({uy, ux});
            }
        }
    }
    return -1;
}

#define K 18
int jump[N*N+1][K];

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++) {
        jump[i][0] = parent[i];
    }
    for (int k = 1; k < K; k++) {
        for (int i = 1; i <= m; i++) {
            jump[i][k] = jump[jump[i][k-1]][k-1];
        }
    }
    for (int i = 1; i <= q; i++) {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        int p1 = in_tree[y1][x1];
        int p2 = in_tree[y2][x2];
        if (depth[p1] < depth[p2]) swap(p1, p2);
        int ans = 0;
        for (int k = K-1; k >= 0; k--) {
            if (depth[p1] - (1<<k) >= depth[p2]) {
                p1 = jump[p1][k];
                ans += (1<<k);
            }
        }
        if (p1 != p2) {
            for (int k = K-1; k >= 0; k--) {
                if (jump[p1][k] != jump[p2][k]) {
                    ans += 2 * (1<<k);
                    p1 = jump[p1][k];
                    p2 = jump[p2][k];
                }
            }
            ans += 2;
        }
        cout << ans << "\n";
    }
}
