#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010, maxl = 50, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
bool mark[maxn][maxn], col_mark[maxn];
int a[maxn][maxn], dis[maxl][maxn][maxn], mn[maxl][maxl], n, m, k, q;
vector<pair<int, int>> vc[maxl];
bool isin(int x, int y) { return x && y && x <= n && y <= m && (!mark[x][y]); }
void bfs(int c) {
  memset(mark, false, sizeof mark);
  memset(col_mark, false, sizeof col_mark);
  memset(mn[c], 63, sizeof mn[c]);
  auto& d = dis[c];
  col_mark[c] = true;
  queue<pair<int, int>> q;
  for (auto u : vc[c]) {
    mark[u.first][u.second] = true;
    d[u.first][u.second] = 0;
    q.push(u);
  }
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    int cur = a[u.first][u.second];
    if (!col_mark[cur])
      for (auto v : vc[cur])
        if (!mark[v.first][v.second]) {
          mark[v.first][v.second] = true;
          d[v.first][v.second] = d[u.first][u.second] + 1;
          q.push(v);
        }
    col_mark[cur] = true;
    for (int i = 0; i < 4; i++) {
      int tx = u.first + dx[i], ty = u.second + dy[i], col = a[tx][ty];
      if (!isin(tx, ty)) continue;
      d[tx][ty] = min(d[u.first][u.second] + 1, mn[c][col] + 1);
      mn[c][col] = min(mn[c][col], d[tx][ty]);
      mark[tx][ty] = true;
      q.push({tx, ty});
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      vc[a[i][j]].push_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 cl = a[r1][c1], _cl = a[r2][c2];
    int ans = min({mn[cl][_cl] + 2, dis[cl][r2][c2] + 1, dis[_cl][r1][c1] + 1});
    for (int c = 1; c <= k; c++)
      ans = min(ans, dis[c][r1][c1] + dis[c][r2][c2] + 1);
    cout << min(ans, abs(r2 - r1) + abs(c2 - c1)) << '\n';
  }
  return 0;
}
