#include <bits/stdc++.h>
using namespace std;
using namespace std;
inline long long pow_mod(long long X, long long N, long long mod) {
  long long res = 1;
  while (N) {
    if (N & 1) res = res * X % mod;
    X = X * X % mod;
    N >>= 1;
  }
  return res;
}
const long long SI = 2e5 + 100;
const bool DBG = 1;
int n, m, k;
int a[1005][1005];
int dis[41][1005][1005];
vector<pair<int, int> > P[41];
bool visco[41];
bool vis[1005][1005];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
inline void get_dis(int from) {
  memset(visco, 0, sizeof(visco));
  memset(vis, 0, sizeof(vis));
  visco[from] = true;
  queue<pair<int, int> > q;
  for (auto it : P[from]) {
    vis[it.first][it.second] = true;
    q.push(it);
    dis[from][it.first][it.second] = 0;
  }
  pair<int, int> ad;
  int c, ty, tx;
  while (q.empty() == false) {
    ad = q.front();
    c = a[ad.first][ad.second];
    q.pop();
    if (visco[c] == false) {
      for (auto it : P[c])
        if (vis[it.first][it.second] == false) {
          vis[it.first][it.second] = true;
          q.push(it);
          dis[from][it.first][it.second] = dis[from][ad.first][ad.second] + 1;
        }
      visco[c] = true;
    }
    for (int i = 0; i < 4; i++) {
      ty = ad.first + dir[i][0];
      tx = ad.second + dir[i][1];
      if (ty < 1 || ty > n || tx < 1 || tx > m) continue;
      if (vis[ty][tx]) continue;
      vis[ty][tx] = true;
      dis[from][ty][tx] = dis[from][ad.first][ad.second] + 1;
      q.push(pair<int, int>(ty, tx));
    }
  }
}
inline void init() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) P[a[i][j]].push_back(pair<int, int>(i, j));
  for (int i = 1; i <= k; i++) get_dis(i);
}
int main() {
  memset(dis, 0x3f, sizeof(dis));
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  init();
  int q;
  int r1, c1, r2, c2, ans;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
    ans = abs(r2 - r1) + abs(c2 - c1);
    for (int i = 1; i <= k; i++)
      ans = min(ans, dis[i][r1][c1] + dis[i][r2][c2] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
