// 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;
        
        priority_queue<array<int, 3>> que;
        vector<vector<bool>> vis(n, vector<bool>(n, 0));
        que.push({-abs(r1-r2) - abs(c1-c2), r1, c1});
        while (que.size()) {
            auto [c, x, y] = que.top();
            que.pop();
            if (vis[x][y]) continue;
            vis[x][y] = 1;
            c = -c;
            c -= abs(x-r2) + abs(y-c2);
            if (x == r2 && y == c2) {
                cout << c << '\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]) {
                    que.push({-c - abs(x2-r2) - abs(y2-c2) - 1, x2, y2});
                }
            }
        }
    }
}
