#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, const T2 &y) {
  if (y < x) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, const T2 &y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &out, const vector<int> &b) {
  for (auto k : b) out << k << ' ';
  return out;
}
const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 1001;
const int K = 41;
const double EPS = 1e-9;
const int DI[]{1, 0, -1, 0};
const int DJ[]{0, 1, 0, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k;
int a[MX][MX];
struct pt {
  int i;
  int j;
  pt() : i(), j() {}
  pt(int _i, int _j) {
    i = _i;
    j = _j;
  }
  pt go(int mv) { return pt(i + DI[mv], j + DJ[mv]); }
  int get() { return a[i][j]; }
  bool ok() { return i >= 0 && j >= 0 && i < n && j < m; }
};
int dist[K][MX][MX];
vector<pt> in[K];
int used[K];
vector<pt> q[2 * K + 2];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      in[--a[i][j]].push_back(pt(i, j));
    }
  }
  for (int c = 0; c < k; ++c) {
    memset(used, 0, sizeof(used));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) dist[c][i][j] = INF;
    used[c] = 1;
    for (auto &p : in[c]) {
      dist[c][p.i][p.j] = 0;
      q[0].push_back(p);
    }
    for (int d = 0; d < 2 * K + 2; ++d) {
      while (q[d].size()) {
        pt p = q[d].back();
        q[d].pop_back();
        if (dist[c][p.i][p.j] < d) continue;
        for (int mv = 0; mv < 4; ++mv) {
          pt to = p.go(mv);
          if (!to.ok() || dist[c][to.i][to.j] <= d + 1) continue;
          int ct = to.get();
          if (!used[ct]) {
            for (auto &pp : in[ct]) {
              dist[c][pp.i][pp.j] = d + 2;
              q[d + 2].push_back(pp);
            }
            used[ct] = 1;
          }
          dist[c][to.i][to.j] = d + 1;
          q[d + 1].push_back(to);
        }
      }
    }
  }
  int reqs;
  cin >> reqs;
  while (reqs--) {
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;
    --i1, --j1, --i2, --j2;
    int ans = abs(i1 - i2) + abs(j1 - j2);
    for (int c = 0; c < k; ++c) {
      mine(ans, dist[c][i1][j1] + dist[c][i2][j2] + 1);
    }
    cout << ans << '\n';
  }
}
