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

#include <iostream>
#include <vector>

using namespace std;

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

struct dat {
    int dl, dr, ul, ur;
    int c;
    
    dat() {}
    
    dat(int _l, int _r, int _c) : c(_c) {
        c = _c;
        dl = ul = _l;
        dr = ur = _r;
    }
    
    dat(int _dl, int _dr, int _ul, int _ur, int _c) :
        dl(_dl), dr(_dr), ul(_ul), ur(_ur), c(_c) {}
};

dat merge(dat a, dat b) {
    int ml = max(a.ul, b.dl);
    int mr = min(a.ur, b.dr);
    int c = max(0, ml - mr);
    
    a.dl = min(a.dr, max(a.dl, ml));
    a.dr = max(a.dl, min(a.dr, mr));
    
    b.ul = min(b.ur, max(b.ul, ml));
    b.ur = max(b.ul, min(b.ur, mr));
    
    return dat(a.dl, a.dr, b.ul, b.ur, a.c + b.c + c);
}

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];
    }
    
    vector<int> l(n), r(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (g[i][j] == '#') {
                if (j == 0 || g[i][j-1] == '.')
                    l[i] = j;
                if (j == n-1 || g[i][j+1] == '.')
                    r[i] = j;
            }
        }
    }
    
    for (int j = 0; j < q; ++j) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        --r1;--c1;--r2;--c2;
        
        dat ans(0, N, 0);
        if (r1 > r2) {
            swap(r1, r2);
            swap(c1, c2);
        }
        for (int i = r1; i < r2; ++i)
            ans = merge(dat(max(l[i], l[i+1]), min(r[i], r[i+1]), 1), ans);
        
        if (ans.dl == ans.dr)
            cout << ans.c + abs(ans.dl - c2) + abs(ans.ul - c1) << '\n';
        else {
            int c3 = min(ans.dr, max(ans.dl, c1));
            cout << ans.c + abs(c3 - c1) + abs(c3 - c2) << '\n';
        }
    }
}
