#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};
int qu[1000 * 1000], n, m, head, cnt;
void bfs(int dd[][1000]) {
  while (cnt) {
    int ij, i, j, d, h;
    ij = qu[cnt--, head++], i = ij / m, j = ij % m;
    d = dd[i][j] + 1;
    for (h = 0; h < 4; h++) {
      int i_ = i + di[h], j_ = j + dj[h];
      if (i_ >= 0 && i_ < n && j_ >= 0 && j_ < m && dd[i_][j_] > d)
        dd[i_][j_] = d, qu[head + cnt++] = i_ * m + j_;
    }
  }
}
int main() {
  static int aa[1000][1000], dd[40][1000][1000], dd_[40][40];
  int k, q, h, h_, i, j;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) scanf("%d", &aa[i][j]), aa[i][j]--;
  for (h = 0; h < k; h++) {
    head = cnt = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++)
        if (aa[i][j] == h)
          dd[h][i][j] = 0, qu[head + cnt++] = i * m + j;
        else
          dd[h][i][j] = n * m + 1;
    bfs(dd[h]);
    for (h_ = 0; h_ < k; h_++) dd_[h][h_] = h == h_ ? 0 : n * m + 1;
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) {
        h_ = aa[i][j];
        dd_[h][h_] = min(dd_[h][h_], dd[h][i][j] + 1);
      }
  }
  for (h = 0; h < k; h++)
    for (i = 0; i < k; i++)
      for (j = 0; j < k; j++) dd_[i][j] = min(dd_[i][j], dd_[i][h] + dd_[h][j]);
  scanf("%d", &q);
  while (q--) {
    int i1, j1, i2, j2, h1, h2, ans;
    scanf("%d%d%d%d", &i1, &j1, &i2, &j2), i1--, j1--, i2--, j2--;
    ans = abs(i1 - i2) + abs(j1 - j2);
    for (h1 = 0; h1 < k; h1++)
      for (h2 = 0; h2 < k; h2++)
        ans = min(ans, dd[h1][i1][j1] + dd_[h1][h2] + 1 + dd[h2][i2][j2]);
    printf("%d\n", ans);
  }
  return 0;
}
