#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U>
inline bool chmin(T& t, const U& u) {
  if (t > u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T, typename U>
inline bool chmax(T& t, const U& u) {
  if (t < u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T, typename Y>
inline T mpow(T a, Y n) {
  T res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k, qq;
  cin >> n >> m >> k;
  VV<int> v(n, V<int>(m));
  VV<int> e(k, V<int>(0));
  VV<int> d(k, V<int>(n * m + k, INF));
  for (int i = 0; i < (ll)(n); ++i) {
    for (int j = 0; j < (ll)(m); ++j) {
      cin >> v[i][j];
      --v[i][j];
      e[v[i][j]].emplace_back(m * i + j);
    }
  }
  queue<int> q;
  int ni, nj;
  for (int i = 0; i < (ll)(k); ++i) {
    V<bool> used(n * m + k, false);
    for (int j = 0; j < (ll)((ll)(e[i]).size()); ++j) {
      used[e[i][j]] = true;
      q.push(e[i][j]);
      q.push(1);
    }
    int now, dis;
    while (q.size()) {
      now = q.front();
      q.pop();
      dis = q.front();
      q.pop();
      chmin(d[i][now], dis);
      for (int l = 0; l < (ll)(4); ++l) {
        ni = now / m + dx[l];
        nj = (now % m) + dy[l];
        if (0 <= ni && 0 <= nj && ni < n && nj < m && !used[ni * m + nj]) {
          used[ni * m + nj] = true;
          q.push(ni * m + nj);
          q.push(dis + 1);
        }
      }
      if (used[n * m + v[now / m][now % m]])
        continue;
      else
        used[n * m + v[now / m][now % m]] = true;
      for (int j = 0; j < (ll)((ll)(e[v[now / m][now % m]]).size()); ++j) {
        int nex = e[v[now / m][now % m]][j];
        if (!used[nex]) {
          used[nex] = true;
          q.push(nex);
          q.push(dis + 1);
        }
      }
    }
  }
  cin >> qq;
  int sx, sy, gx, gy, ans;
  while (qq--) {
    cin >> sx >> sy >> gx >> gy;
    --sx;
    --sy;
    --gx;
    --gy;
    ans = abs(sx - gx) + abs(sy - gy);
    for (int i = 0; i < (ll)(k); ++i) {
      chmin(ans, -1 + d[i][m * sx + sy] + d[i][m * gx + gy]);
    }
    cout << ans << '\n';
  }
}
