#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int a[MAXN][MAXN];
int dist[41][MAXN][MAXN];
int n, m, k;
int vis[45];
vector<pair<int, int>> allcol[45];
int P[] = {1, -1, 0, 0};
int Q[] = {0, 0, -1, 1};
const int INF = 1e9;
inline bool chk(int x, int y) { return x <= n && x >= 1 && y <= m && y >= 1; }
void adfsdfas(int col) {
  queue<pair<int, int>> bfs;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == col)
        bfs.push({i, j}), dist[col][i][j] = 0;
      else
        dist[col][i][j] = INF;
      vis[a[i][j]] = 0;
    }
  while (!bfs.empty()) {
    auto xy = bfs.front();
    bfs.pop();
    int x = xy.first, y = xy.second;
    if (!vis[a[x][y]]) {
      vis[a[x][y]] = 1;
      for (auto ij : allcol[a[x][y]]) {
        int tx = ij.first, ty = ij.second;
        if (dist[col][tx][ty] == INF) {
          dist[col][tx][ty] = dist[col][x][y] + 1;
          bfs.push({tx, ty});
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int tx = x + P[i], ty = y + Q[i];
      if (chk(tx, ty) && dist[col][tx][ty] == INF) {
        dist[col][tx][ty] = dist[col][x][y] + 1;
        bfs.push({tx, ty});
      }
    }
  }
}
inline int d(int x1, int y1, int x2, int y2) {
  return abs(y2 - y1) + abs(x2 - x1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> a[i][j], allcol[a[i][j]].push_back({i, j});
  for (int i = 1; i <= k; i++) adfsdfas(i);
  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int mn = d(r1, c1, r2, c2);
    for (int i = 1; i <= k; i++)
      mn = min(mn, dist[i][r1][c1] + dist[i][r2][c2] + 1);
    cout << mn << '\n';
  }
}
