#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
  assert(n > 0);
  int ans = -1;
  while (n) {
    ans++;
    n >>= 1;
  }
  return ans;
}
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> grid(n, vector<int>(m));
  vector<vector<pair<int, int>>> pos(k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      grid[i][j]--;
      pos[grid[i][j]].emplace_back(i, j);
    }
  }
  auto inrange = [&](const pair<int, int> &p) {
    return 0 <= p.first && p.first < n && 0 <= p.second && p.second < m;
  };
  const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  vector<vector<vector<int>>> dist(k,
                                   vector<vector<int>>(n, vector<int>(m, -1)));
  auto bfs = [&](int col) {
    vector<int> jump(k, 0);
    queue<pair<int, int>> q;
    for (auto p : pos[col]) {
      q.push(p);
      dist[col][p.first][p.second] = 0;
    }
    jump[col] = 1;
    while (!q.empty()) {
      auto [x, y] = q.front();
      q.pop();
      int cur = grid[x][y];
      if (!jump[cur]) {
        jump[cur] = true;
        for (auto [i, j] : pos[cur]) {
          if (dist[col][i][j] == -1) {
            dist[col][i][j] = dist[col][x][y] + 1;
            q.push(make_pair(i, j));
          }
        }
      }
      for (int i = 0; i < 4; i++) {
        int nxtx = x + dx[i], nxty = y + dy[i];
        if (inrange(make_pair(nxtx, nxty)) && dist[col][nxtx][nxty] == -1) {
          dist[col][nxtx][nxty] = dist[col][x][y] + 1;
          q.push(make_pair(nxtx, nxty));
        }
      }
    }
  };
  for (int i = 0; i < k; i++) {
    bfs(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--, c1--, r2--, c2--;
    int ans = abs(r1 - r2) + abs(c1 - c2);
    for (int i = 0; i < k; i++) {
      ans = min(ans, dist[i][r1][c1] + 1 + dist[i][r2][c2]);
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
