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

#include <iostream>
#include <vector>

using namespace std;

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

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;
        cout << abs(r1 - r2) + abs(c1 - c2) << '\n';
    }
}
