#include <bits/stdc++.h>
using namespace std;
short dist[44][1212][1212];
int M[1212][1212], n, m, k;
struct xy {
  int x, y;
};
vector<xy> L[44];
int is_spread[44];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void bfs(int col) {
  deque<xy> Q;
  int i, j;
  for (i = 1; i <= k; i++) is_spread[i] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) dist[col][i][j] = -1;
  for (auto p : L[col]) {
    Q.push_back(p);
    dist[col][p.x][p.y] = 0;
  }
  is_spread[col] = 1;
  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop_front();
    int nxt_col = M[p.x][p.y], D = dist[col][p.x][p.y];
    if (!is_spread[nxt_col]) {
      for (auto p : L[nxt_col]) {
        if (dist[col][p.x][p.y] == -1) {
          Q.push_back(p);
          dist[col][p.x][p.y] = D + 1;
        }
      }
      is_spread[nxt_col] = 1;
    }
    for (int i = 0; i < 4; i++) {
      int nx = p.x + dx[i];
      int ny = p.y + dy[i];
      if (dist[col][nx][ny] == -1) {
        Q.push_back({nx, ny});
        dist[col][nx][ny] = D + 1;
      }
    }
  }
}
int jd(int x) {
  if (x < 0) return -x;
  return x;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &M[i][j]);
      L[M[i][j]].push_back({i, j});
    }
  for (i = 1; i <= k; i++) bfs(i);
  int q;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int sx, sy, ex, ey;
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    int mini = 1e9;
    for (int p = 1; p <= k; p++) {
      int D = dist[p][sx][sy] + dist[p][ex][ey] + 1;
      mini = min(mini, D);
    }
    printf("%d\n", min(mini, jd(sx - ex) + jd(sy - ey)));
  }
  return 0;
}
