#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, L = 1e3 + 5, C = 50, INF = 0x3f3f3f3f;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n, m, k, Q;
int color[L][L];
vector<pair<int, int> > points[N];
int dis[C][N];
bool vis[N], cor[C];
pair<int, int> q[N];
void bfs(int c) {
  memset(cor, false, sizeof cor);
  int hh = 0, tt = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      vis[i * m + j] = false;
      if (color[i][j] != c)
        dis[c][i * m + j] = INF;
      else
        q[++tt] = {i, j}, vis[i * m + j] = true;
    }
  while (hh <= tt) {
    auto t = q[hh++];
    int a = t.first, b = t.second;
    for (int i = 0; i < 4; i++) {
      int x = a + dx[i], y = b + dy[i];
      if (x < 0 || x >= n || y < 0 || y >= m || vis[x * m + y] ||
          dis[c][x * m + y] != INF)
        continue;
      dis[c][x * m + y] = dis[c][a * m + b] + 1;
      q[++tt] = {x, y};
      vis[x * m + y] = true;
    }
    if (!cor[color[a][b]]) {
      cor[color[a][b]] = true;
      for (auto t : points[color[a][b]]) {
        int x = t.first, y = t.second;
        if (vis[x * m + y] || dis[c][x * m + y] != INF) continue;
        dis[c][x * m + y] = dis[c][a * m + b] + 1;
        q[++tt] = {x, y};
        vis[x * m + y] = true;
      }
    }
  }
  return;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &color[i][j]);
      points[color[i][j]].push_back({i, j});
    }
  for (int i = 1; i <= k; i++) bfs(i);
  scanf("%d", &Q);
  while (Q--) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    a--, b--, c--, d--;
    if (a == c && b == d) {
      printf("0\n");
      continue;
    }
    int res = abs(a - c) + abs(b - d);
    for (int i = 1; i <= k; i++)
      res = min(res, dis[i][a * m + b] + dis[i][c * m + d] + 1);
    printf("%d\n", res);
  }
  return 0;
}
