#include <bits/stdc++.h>
using namespace std;
const int maxS = 1 << 20, maxK = 52;
bool seen[maxK][maxK];
int n, m, k, A[maxS], D[maxK][maxS], Dx[4] = {0, +1, 0, -1},
                                     Dy[4] = {+1, 0, -1, 0};
vector<int> C[maxK];
inline int ID(int x, int y) { return x << 10 | y; }
inline int N(int id, int d, int c) {
  int x = (id >> 10) + Dx[d];
  int y = (id & ((1 << 10) - 1)) + Dy[d];
  if (0 <= x && x <= n && 0 <= y && y <= m && !D[c][ID(x, y)]) return ID(x, y);
  return -1;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int id = ID(i, j);
      cin >> A[id];
      C[A[id]].push_back(id);
    }
  for (int c = 1; c <= k; c++) {
    queue<int> Q;
    for (int id : C[c]) {
      D[c][id] = 1;
      Q.push(id);
    }
    seen[c][c] = true;
    while (Q.size()) {
      int id = Q.front();
      Q.pop();
      if (!seen[c][A[id]]) {
        for (int a : C[A[id]])
          if (D[c][a] == 0) {
            D[c][a] = D[c][id] + 1;
            Q.push(a);
          }
        seen[c][A[id]] = true;
      }
      for (int d = 0; d < 4; d++) {
        int a = N(id, d, c);
        if (a == -1) continue;
        D[c][a] = D[c][id] + 1;
        Q.push(a);
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;
    int Ans = abs(x1 - x2) + abs(y1 - y2);
    int P1 = ID(x1, y1), P2 = ID(x2, y2);
    for (int c = 1; c <= k; c++) Ans = min(Ans, D[c][P1] + D[c][P2] - 1);
    cout << Ans << "\n";
  }
}
