#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
const int K = 45;
int n, m, k;
int grid[N][N], dist[K][N][N];
int lx[4] = {1, -1, 0, 0};
int ly[4] = {0, 0, -1, 1};
deque<pair<int, int> > color[K];
void bfs(int dist[N][N], deque<pair<int, int> > Q) {
  static int f[K];
  memset(f, 0, sizeof(f));
  while (!Q.empty()) {
    pair<int, int> u = Q.front();
    Q.pop_front();
    int x = u.first, y = u.second;
    if (f[grid[x][y]] == 0) {
      f[grid[x][y]] = 1;
      auto it = color[grid[x][y]].begin();
      for (; it != color[grid[x][y]].end(); it++) {
        int xx = it->first, yy = it->second;
        if (dist[xx][yy] <= dist[x][y] + 1) continue;
        dist[xx][yy] = dist[x][y] + 1;
        Q.push_back({xx, yy});
      }
    }
    for (int i = 0; i < 4; i++) {
      int xx = x + lx[i], yy = y + ly[i];
      if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
      if (dist[x][y] + 1 >= dist[xx][yy]) continue;
      dist[xx][yy] = dist[x][y] + 1;
      Q.push_back({xx, yy});
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  memset(dist, 63, sizeof(dist));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
      color[grid[i][j]].push_back({i, j});
      dist[grid[i][j]][i][j] = 0;
    }
  for (int i = 1; i <= k; i++) bfs(dist[i], color[i]);
  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = abs(r1 - r2) + abs(c2 - c1);
    for (int i = 1; i <= k; i++)
      ans = min(ans, dist[i][r1][c1] + dist[i][r2][c2] + 1);
    cout << ans << endl;
  }
}
