#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Min(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void Max(T &a, T b) {
  a = max(a, b);
}
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 15;
const int K = 45;
int n, m, k, t, a[N][N];
vector<pair<int, int> > cl[K];
inline bool check(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
pair<int, int> q[N * N];
int ql, qr;
int d[K][N][N];
bool used[K];
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]);
      cl[a[i][j]].push_back({i, j});
    }
  memset(d, 0x3f, sizeof(d));
  for (int i = 1; i <= k; ++i) {
    ql = 0, qr = -1;
    memset(used, 0, sizeof(used));
    for (pair<int, int> e : cl[i]) {
      q[++qr] = {e.first, e.second};
      d[i][e.first][e.second] = 0;
    }
    used[i] = true;
    while (ql <= qr) {
      int x = q[ql].first, y = q[ql].second;
      ++ql;
      for (int j = 0; j < 4; ++j) {
        int tox = dx[j] + x, toy = dy[j] + y;
        if (check(tox, toy) && d[i][tox][toy] == inf) {
          d[i][tox][toy] = d[i][x][y] + 1;
          q[++qr] = {tox, toy};
        }
      }
      if (!used[a[x][y]]) {
        used[a[x][y]] = true;
        for (pair<int, int> e : cl[a[x][y]])
          if (d[i][e.first][e.second] == inf) {
            d[i][e.first][e.second] = d[i][x][y] + 1;
            q[++qr] = {e.first, e.second};
          }
      }
    }
  }
  scanf("%d", &t);
  while (t--) {
    int x1, abcde, x2, y2;
    scanf("%d %d %d %d", &x1, &abcde, &x2, &y2);
    int res = abs(x2 - x1) + abs(y2 - abcde);
    for (int i = 1; i <= k; ++i) Min(res, d[i][x1][abcde] + 1 + d[i][x2][y2]);
    printf("%d\n", res);
  }
  return 0;
}
