#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 1e3 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, m, q, k;
int dis[N][N][45], cc[N][N];
bool vis[N];
vector<pii> col[45];
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void bfs(int c) {
  queue<pii> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) dis[i][j][c] = INF;
  memset(vis, 0, sizeof(vis));
  for (auto x : col[c]) {
    q.push({x.first, x.second});
    dis[x.first][x.second][c] = 0;
    vis[c] = 1;
  }
  while ((int)q.size()) {
    auto u = q.front();
    q.pop();
    if (!vis[cc[u.first][u.second]]) {
      vis[cc[u.first][u.second]] = 1;
      for (auto tmp : col[cc[u.first][u.second]]) {
        if (dis[tmp.first][tmp.second][c] == INF) {
          dis[tmp.first][tmp.second][c] = dis[u.first][u.second][c] + 1;
          q.push(tmp);
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      int x = u.first + dir[i][0], y = u.second + dir[i][1];
      if (x >= 1 && y >= 1 && x <= n && y <= m && dis[x][y][c] == INF) {
        dis[x][y][c] = dis[u.first][u.second][c] + 1;
        q.push({x, y});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> cc[i][j];
      col[cc[i][j]].emplace_back(i, j);
    }
  }
  for (int i = 1; i <= k; i++) bfs(i);
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = abs(r1 - r2) + abs(c1 - c2);
    for (int c = 1; c <= k; c++)
      ans = min(ans, dis[r1][c1][c] + dis[r2][c2][c] + 1);
    cout << ans << '\n';
  }
  return 0;
}
