// Subtasks:
// 1: AC
// _: TLE

#include <array>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const int N = 1010;
string g[N];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    int n, q;
    cin >> n >> q;
    
    for (int i = 0; i < n; ++i) {
        cin >> g[i];
    }
    
    for (int i = 0; i < q; ++i) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        --r1;--c1;--r2;--c2;
        
        queue<array<int, 3>> bfs;
        vector<vector<bool>> vis(n, vector<bool>(n, 0));
        bfs.push({r1, c1, 0});
        vis[r1][c1] = 1;
        while (bfs.size()) {
            auto [x, y, d] = bfs.front();
            bfs.pop();
            if (x == r2 && y == c2) {
                cout << d << '\n';
                break;
            }
            for (int j = 0; j < 4; ++j) {
                int x2 = x + dx[j];
                int y2 = y + dy[j];
                if (0 <= x2 && x2 < n && 0 <= y2 && y2 < n && g[x2][y2] == '#' && !vis[x2][y2]) {
                    bfs.push({x2, y2, d+1});
                    vis[x2][y2] = 1;
                }
            }
        }
    }
}
