#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
const int INF = 1e9;
vector<pair<int, int>> adj[MAXN];
int di[MAXN];
int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
vector<array<int, 4>> qs;
vector<int> res[400400];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  int sz = n * m;
  vector<vector<int>> col(n, vector<int>(m));
  auto f = [&](int i, int j) -> int { return m * i + j; };
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> col[i][j];
      col[i][j]--;
      adj[f(i, j)].push_back({col[i][j] + sz, 1});
      adj[col[i][j] + sz].push_back({f(i, j), 1});
      for (int k = 0; k < 4; k++) {
        int ni = i + dx[k], nj = j + dy[k];
        if (ni < n && nj < m && ni >= 0 && nj >= 0)
          adj[f(i, j)].push_back({f(ni, nj), 2});
      }
    }
  }
  map<pair<int, int>, int> to;
  vector<pair<int, int>> ps;
  int q, cur = 0;
  cin >> q;
  while (q--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    if (!to.count({x1, y1})) {
      to[{x1, y1}] = cur++;
      ps.push_back({x1, y1});
    }
    if (!to.count({x2, y2})) {
      to[{x2, y2}] = cur++;
      ps.push_back({x2, y2});
    }
    qs.push_back({x1, y1, x2, y2});
  }
  for (int co = 0; co < k; co++) {
    fill(di, di + MAXN, INF);
    di[sz + co] = 0;
    queue<pair<int, int>> q1, q2;
    q1.push({0, sz + co});
    while (q1.size() || q2.size()) {
      pair<int, int> p;
      if (q1.empty()) {
        p = q2.front();
        q2.pop();
      } else if (q2.empty()) {
        p = q1.front();
        q1.pop();
      } else {
        if (q1.front().first <= q2.front().first) {
          p = q1.front();
          q1.pop();
        } else {
          p = q2.front();
          q2.pop();
        }
      }
      int u = p.second, d = p.first;
      if (d > di[u]) continue;
      for (auto e : adj[u]) {
        int v = e.first, w = e.second;
        if (di[v] > d + w) {
          di[v] = d + w;
          if (w == 1)
            q1.push({di[v], v});
          else
            q2.push({di[v], v});
        }
      }
    }
    for (int i = 0; i < ps.size(); i++)
      res[i].push_back(di[f(ps[i].first, ps[i].second)]);
  }
  for (auto x : qs) {
    int ans = abs(x[0] - x[2]) + abs(x[1] - x[3]);
    int u = to[{x[0], x[1]}], v = to[{x[2], x[3]}];
    for (int i = 0; i < k; i++) ans = min(ans, (res[u][i] + res[v][i]) / 2);
    cout << ans << '\n';
  }
}
