#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, k, a[maxn][maxn], dis[42][maxn][maxn], dx[5], dy[5], d[maxn][maxn], _;
struct da {
  int x, y;
} q[maxn * maxn];
vector<da> po[50];
bool f[maxn][maxn], v[50];
inline bool ok(int x, int y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m && !f[x][y]) return 1;
  return 0;
}
void solve(int col) {
  memset(f, 0, sizeof f);
  memset(v, 0, sizeof v);
  int l = 1, r = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == col) q[++r] = {i, j}, f[i][j] = 1;
  while (l <= r) {
    da now = q[l++];
    for (int i = 0; i < 4; ++i)
      if (ok(now.x + dx[i], now.y + dy[i])) {
        f[now.x + dx[i]][now.y + dy[i]] = 1;
        dis[col][now.x + dx[i]][now.y + dy[i]] = dis[col][now.x][now.y] + 1;
        q[++r] = {now.x + dx[i], now.y + dy[i]};
      }
    if (!v[a[now.x][now.y]]) {
      v[a[now.x][now.y]] = 1;
      for (auto j : po[a[now.x][now.y]])
        if (ok(j.x, j.y)) {
          f[j.x][j.y] = 1;
          dis[col][j.x][j.y] = dis[col][now.x][now.y] + 1;
          q[++r] = {j.x, j.y};
        }
    }
  }
}
int main() {
  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]), po[a[i][j]].push_back({i, j});
  dx[0] = 1;
  dy[0] = 0;
  dx[1] = -1;
  dy[1] = 0;
  dx[2] = 0;
  dy[2] = 1;
  dx[3] = 0;
  dy[3] = -1;
  for (int col = 1; col <= k; col++) solve(col);
  for (scanf("%d", &_); _; _--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int ans = abs(x1 - x2) + abs(y1 - y2);
    for (int i = 1; i <= k; i++)
      ans = min(ans, dis[i][x1][y1] + dis[i][x2][y2] + 1);
    printf("%d\n", ans);
  }
  return 0;
}
