#include <bits/stdc++.h>
using pii = std::pair<int, int>;
const int N = 1010;
const int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int n, m, i, j, k;
int col[N][N];
bool usecol[45];
int dis[N * N][45];
std::vector<int> colE[45];
inline int id(int x, int y) { return 1ll * (x - 1) * m + 1ll * y; }
inline pii unid(int x) {
  return std::make_pair((x - (x % m == 0 ? m : x % m)) / m + 1,
                        x % m == 0 ? m : x % m);
}
inline void bfs(int c) {
  std::queue<int> q;
  for (int pos : colE[c]) {
    dis[pos][c] = 0;
    q.push(pos);
  }
  usecol[c] = 1;
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    pii P = unid(pos);
    int x = P.first, y = P.second, nowc = col[x][y];
    if (!usecol[nowc]) {
      usecol[nowc] = 1;
      for (int nxt : colE[nowc]) {
        if (dis[pos][c] + 1 < dis[nxt][c]) {
          dis[nxt][c] = dis[pos][c] + 1;
          q.push(nxt);
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int nxtx = x + dir[i][0], nxty = y + dir[i][1], nxt = id(nxtx, nxty);
      if (nxtx < 1 || nxtx > n || nxty < 1 || nxty > m) {
        continue;
      }
      if (dis[pos][c] + 1 < dis[nxt][c]) {
        dis[nxt][c] = dis[pos][c] + 1;
        q.push(nxt);
      }
    }
  }
}
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", &col[i][j]);
      colE[col[i][j]].push_back(id(i, j));
    }
  }
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 1; i <= k; i++) {
    memset(usecol, 0, sizeof(usecol));
    bfs(i);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int r1, c1, r2, c2;
    scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
    int ans = std::abs(r1 - r2) + std::abs(c1 - c2), idS = id(r1, c1),
        idT = id(r2, c2);
    for (int i = 1; i <= k; i++) {
      ans = std::min(ans, dis[idS][i] + dis[idT][i] + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
