#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void chkmin(T &a, const T &b) {
  a = a < b ? a : b;
}
template <typename T>
inline void chkmax(T &a, const T &b) {
  a = a > b ? a : b;
}
const int MAXN = 1005, MAXK = 45, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int mp[MAXN][MAXN], vis[MAXK], n, m, K;
struct P {
  int x, y;
} que[MAXN * MAXN];
vector<P> clr[MAXK];
short dis[MAXK][MAXN][MAXN];
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &mp[i][j]);
      clr[mp[i][j]].push_back(P{i, j});
    }
  for (int i = 1; i <= K; i++) {
    int he = 1, ta = 0;
    memset(dis[i], -1, sizeof(dis[i]));
    memset(vis, 0, sizeof(vis));
    for (const P &p : clr[i]) {
      que[++ta] = p;
      dis[i][p.x][p.y] = 0;
    }
    vis[i] = 1;
    while (he <= ta) {
      const P &u = que[he++];
      short d = dis[i][u.x][u.y];
      int c = mp[u.x][u.y];
      for (int j = 0; j < 4; j++) {
        int x = u.x + dx[j], y = u.y + dy[j];
        if (x > 0 && x <= n && y > 0 && y <= m && dis[i][x][y] < 0) {
          dis[i][x][y] = d + 1;
          que[++ta] = P{x, y};
        }
      }
      if (!vis[c]) {
        vis[c] = 1;
        for (const P &v : clr[c]) {
          if (dis[i][v.x][v.y] < 0) {
            dis[i][v.x][v.y] = d + 1;
            que[++ta] = P{v.x, v.y};
          }
        }
      }
    }
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int res = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= K; i++)
      chkmin(res, 1 + dis[i][x1][y1] + dis[i][x2][y2]);
    printf("%d\n", res);
  }
  return 0;
}
