#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e3;
const int maxK = 40;
int d[maxK][maxN][maxN];
int a[maxN][maxN];
vector<pair<int, int>> b[maxK];
vector<int> goX = {-1, 0, 1, 0};
vector<int> goY = {0, 1, 0, -1};
int n, m, k;
void go(int col) {
  queue<pair<int, int>> q;
  for (auto& p : b[col]) {
    d[col][p.first][p.second] = 0;
    q.push(p);
  }
  vector<bool> used(k);
  used[0] = true;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    if (!used[a[p.first][p.second]]) {
      for (auto& pp : b[a[p.first][p.second]]) {
        if (d[col][p.first][p.second] + 1 < d[col][pp.first][pp.second]) {
          d[col][pp.first][pp.second] = d[col][p.first][p.second] + 1;
          q.push(pp);
        }
      }
      used[a[p.first][p.second]] = true;
    }
    for (int i = 0; i < 4; i++) {
      int x = p.first + goX[i];
      int y = p.second + goY[i];
      if (x >= 0 && y >= 0 && x < n && y < m &&
          d[col][p.first][p.second] + 1 < d[col][x][y]) {
        d[col][x][y] = d[col][p.first][p.second] + 1;
        q.push({x, y});
      }
    }
  }
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][j]--;
      b[a[i][j]].push_back({i, j});
    }
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      for (int c = 0; c < m; c++) {
        d[i][j][c] = INF;
      }
    }
  }
  for (int col = 0; col < k; col++) {
    go(col);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    int ans = abs(x2 - x1) + abs(y2 - y1);
    for (int j = 0; j < k; j++) {
      ans = min(ans, d[j][x1][y1] + d[j][x2][y2] + 1);
    }
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) solve();
}
